Linux下通过FTP来备份Mysql数据/zz/

#!/bin/bash
host=202.100.222.2   #FTP主机
UserName=test    #FTP用户名
Passwd=test        #FTP密码

 

function Iint() #处理涵数
{
backup_path=/home/mysqlbackup   #压缩文件存放的目录
file=$path-mysql-$(date +%Y-%m-%d).tar.gz #文件名
backupCWD=/usr/local/mysql/data/$path   #需备份的path
tar -Pczf $backup_path/$file $backupCWD #执行备份操作

cd $backup_path
ftp -i -n <<!
open $host
user $UserName $Passwd

cd MYSQL-BACK/$path
put   $file
bye
!
}
/etc/init.d/mysqld stop >/dev/null 2>&1 #停止Mysql服务
path=database1 #需备份的数据名
Iint #调用处理涵数
path=datebase2
Iint
/etc/init.d/mysqld start >/dev/null 2>&1 #启动Mysql服务

rm -rf $backup_path/*.tar.gz #删除压缩文件
echo “ftp back ok!”

发表评论

邮箱地址不会被公开。 必填项已用*标注