Aug 27, 2007

Autobackup of mysql and then ftp to other PC from linux

push.sh : script

1: mysqldump --add-drop-table -C -l -pPASSWORD -r /home/root/dbbackup DBNAME
2: Today="`date +%d%b%y_%H%M`"
3: mv /home/root/dbbackup /home/root/dbbackup_$Today
4: cp /home/root/dbbackup* /backup/ (This creates a backup on same PC ).
5: /usr/local/bin/ncftpput -u sql -p sql123 -V 172.x.x.x (FTP server IP) . /home/root/dbbackup*
6: rm -rf /home/root/dbbackup*

Explantion : First backup of database then define variable with current date & time.
Append variable to filename and copy it to a folder. From their do ncftp to an ftp server and then finally from the local folder delete all the files.

To repeat the procedure use cron:

crontab -e
59 10 * * 1-7 /home/root/push.sh
minute hour day(0-31) month(0-12) day of week(1-7)

: /var/spool/cron/ folder will contain
59 10 * * 1-7 /home/root/push.sh

No comments: