Linux下通过FTP来备份Mysql数据[原创]

来源:百度文库 编辑:神马文学网 时间:2024/04/28 16:17:13
希望对大家有用。
[CODE]
#!/bin/bash
############### Mysql Backup & FTP ################
#Power By Lts 2004-12-23 16:10
#E-mail:tiansi@liu.net.cn
#http://www.181info.net
#1. mkdir /home/mysqlbackup
#2. chmod 700 MysqlDatebackup.sh
#3. vi /etc/crontab , 30 03 * * * root /home/mysqlbackup/MysqlDatebackup.sh
#everyday 03:30 the MysqlDatebackup.sh will work
#System Setup
host=202.100.222.2 #ftp host
UserName=test #ftp user name
Passwd=test #fto user password
function Iint()
{
backup_path=/home/mysqlbackup #set saved backup path
file=$path-mysql-$(date +%Y-%m-%d).tar.gz
backupCWD=/usr/local/mysql/data/$path #set backup file,the mysql path
tar -czf $backup_path/$file $backupCWD
#file tar
cd $backup_path
#file ftp
ftp -i -n < open $host
user $UserName $Passwd
if [ ! [ -d WEB-BACK/$path ]]; then
mkdir MYSQL-BACK/$path
fi
cd MYSQL-BACK/$path
put $file
bye
!
}
/etc/init.d/mysqld stop >/dev/null 2>&1
path=database1 #datebase1
Iint
path=datebase2 #datebase2
Iint
/etc/init.d/mysqld start >/dev/null 2>&1
rm -rf $backup_path/*.tar.gz
echo "ftp back ok!"
[/CODE]