Tag Archives: linux

Backup your MySQL server nightly – using e-mail and ftp

Wanted to create backups at certain intervals for a very important server. And what’s more  I wanted to make sure that the backups were in couple of places. Including my e-mail. So, I bash script was created!

#!/bin/bash
### MySQL Server Login Info ###
MUSER="some_mysql_user"
MPASS="some_mysql_password"
MHOST="localhost"
MYSQL="mysql"
MYSQLDUMP="mysqldump"
BAK="/var/www/backup/mysql/"
GZIP="$(which gzip)"
### FTP SERVER Login info ###
FTPU="some_ftp_user"
FTPP="some_ftp_password"
FTPS="some_ftp_server_information"
NOW=$(date +"%d-%m-%Y")
#E-mail info
EMAIL="some@email.com"

[ ! -d $BAK ] && mkdir -p $BAK || /bin/rm -f $BAK/*

mysqldump -u root -p$MPASS -h $MHOST --all-databases | gzip -9 > /var/www/backup/backup_$NOW.sql.gz

lftp -u $FTPU,$FTPP -e "mput /var/www/backup/backup_$NOW.sql.gz; quit" $FTPS
mutt -s "Full database backup" $EMAIL < message2.txt  -a /var/www/backup/backup_$NOW.sql.gz

Now you may notice you will need to install couple of packages to your server. These are ;

  • Mutt : Setting mutt is very easy. Simply search gmail mutt configuration in google. Who knows. May be you will find me in the process.
  • lftp : You don’t need to set this. And the packages for this is readily available for ubuntu and fedora distros.

Now all you need is to save this little script and call it from cron in periods of your wish.

For those wondering what message2.txt contains. It is a daily usage report that is created by a python script I wrote. However you can simply create a simple txt file of your choosing. That way mutt will include that text in to your e-mail.

 

Image Capturing from WebCAM using OpenCV and Pygame in Python

I know there a lot of examples of WebCAM image capturing on the net. Mine is one of that but the main difference is that this little script here simply captures frames in a certain fps and simply saves those images. There a numerous usages for such a thing. One usage could be a script that uploads this image to a certain ftp site so you can display it in your web page. I needed this little script to follow a moving object. I did not write the whole script. You may think this as a little upgrade from the one on the internet. The script uses OpenCV and Pygame libs. Without further ado the script :

import pygame
import Image
from pygame.locals import *
import sys

import opencv
import cv

#this is important for capturing/displaying images
from opencv import highgui

camera = highgui.cvCreateCameraCapture(0)
i=0
def get_image():
    im = highgui.cvQueryFrame(camera)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    #convert Ipl image to PIL image
    return opencv.adaptors.Ipl2PIL(im)

fps = 25.0
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("WebCAM Demo")
screen = pygame.display.get_surface()

while True:
    events = pygame.event.get()
    for event in events:
        if event.type == QUIT or event.type == KEYDOWN:
            sys.exit(0)
    im = get_image()
    if i>100:
	#allowing the camera to focus
	#auto focus is really annoying
        im.save("image_"+str(i)+"", "JPEG")
    i=i+1
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)

    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))

Getting raw data from a USB mouse in Linux using Python

If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got me started. Once I beautify my multiple-mouse code I will be posting it here as well. Without further ado :

mouse = file('/dev/input/mouse0')
while True:
    status, dx, dy = tuple(ord(c) for c in mouse.read(3))

    def to_signed(n):
        return n - ((0x80 & n) << 1)
        
    dx = to_signed(dx)
    dy = to_signed(dy)
    print "%#02x %d %d" % (status, dx, dy)

I hope this just made your day!

Setting up a CVS server for the BlackBox project

Following the previous posts in this category you will notice that I was using Sourceforge.net as the code hosting. We had to change that because we really didn’t want to share every bit of code. ( A big sorry to open source developers. I am truly a sell out. ) So had to set up CVS server. Never done that before. Should probably add it to my CV. Anyways to business.

How to set up a CVS server using SSH :

Continue reading

Installing Ångström Linux on BeagleBoard

We have been able to install Ångström Linux to our beagle board. Ran into couple problems. The first one was we trusted BeagleBoard Beginners wiki just too much!!

You see we learned that we should NOT set any environment variables while using demo u-boot image which was downloaded from here. In fact what we did is we created our own Ångström image (from Ångström site) and simply installed that to our Linux partition of our SDHC card. And it worked beautifully. Though I must say first boot is a drag, very very slow.

Continue reading

Upgrading Fedora from 11 to 12

f12launch

Have just upgraded my dual-boot (WindowsVista/Fedora 11) laptop (HP Compaq Presario CQ50). I simply downloaded an upgrade ISO from https://fedoraproject.org/get-fedora . Than burned it to a DVD. Started my Fedora 11 and updated it by calling in the command “yum update”. Restarted the laptop with the DVD in and voilà I had my computer updated. Had some trouble with the household though because I was updating my desktop (WindowsXP/OpenSUSE) and my borrowed other laptop (Fedora 11) at the same time.

Continue reading

The BeagleBoard Has Arrived!!

The long awaited Beagle board has arrived.

[flagallery gid=1 name="Gallery"]

Even tough the team’s enthusiasm was up the roof we were not able to try it out. More on this later. I would also like to inform all people who is following this blog religiously that our project is now hosted on SourceForge.net at http://sourceforge.net/projects/theblackbox/ . And I have also set up a CVS so those who want to follow the code will be able to follow it from the net.

The CVS code is as follows

cvs -d:pserver:anonymous@theblackbox.cvs.sourceforge.net:/cvsroot/theblackbox login

cvs -z3 -d:pserver:anonymous@theblackbox.cvs.sourceforge.net:/cvsroot/theblackbox co -P modulename

I am sorry to say due to some weird problem you can not view the CVS modules from Sourceforge. You will need to use some kind of client. I am currently using Eclipse as my development IDE hence all my CVS materials comes from that. I have heard that TortoiseCVS is quite neat in its own way (for Windows) but I’d rather use Eclipse your choice.

Continue reading