############### MySQL Backup & FTP ################
#Power By SBear 2004-01-20 2:10
#E-mail:[email protected]
#http://www.1842.net
#http://www.CnLinux.net
#1. mkdir /home/backup
#2. chmod 700 MySQLbackup.sh
#3. vi /etc/crontab , 30 03 * * * root /home/backup/MySQLbackup.sh
#everyday 03:30 the MySQLbackup.sh will work
#System Setup
host=192.168.0.3 #ftp host
UserName=ftp #ftp user name
Passwd=ftp #fto user password
#stop mysql database server
/usr/bin/killall mysqld
#/etc/rc.c/init.d/mysqld stop
sleep 5s #stop 5 second
#file tar
tar -czf $backup_path/$file $backupCWD
sleep 10s
#start mysql database server
/usr/local/mysql/bin/mysqld_safe --user=mysql & #set your mysqld path
#/etc/rc.d/init.d/mysqld start
cd $backup_path
sleep 1s
#file ftp
ftp -i -n <<!
open $host
user $UserName $Passwd
put $file
bye
!
sleep 10s
rm -rf $backup_path/$file[/code:1]
DBbackup.sh 是备份单个数据库的数据
[code:1]#!/bin/bash
############### MySQL One DataBase's Backup & FTP ################
#Power By SBear 2004-01-20 2:40
#E-mail:[email protected]
#http://www.1842.net
#http://www.CnLinux.net
#1. mkdir /home/backup
#2. chmod 700 DBbackup.sh
#3. vi /etc/crontab , 30 03 * * * root /home/backup/DBbackup.sh
#everyday 03:30 the DBbackup.sh will work
#System Setup
#ftp Info
host=192.168.0.3 #ftp host
UserName=ftp #ftp user name
Passwd=ftp #fto user password
#MySQL Info
SQL_host=localhost #MySQL host
SQL_User=root #MySQL UserName
SQL_Passwd=abc #User Password
SQL_db=test #database name
backup_path=/home/backup #set saved backup path
file=$SQL_db-$(date +%Y%m%d).tar.gz
MySQL_path=/usr/local/mysql/bin #set the mysql database bin path