Linux操作系统下通过FTP来备份Mysql数据

网络整理 - 08-07

#!/bin/bash

Mysql Backup & FTP

#Power By Lts 2004-12-23 16:10#E-mail:tiansi@liu.net.cn##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 Setuphost=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 #需备份的pathtar -czf $backup_path/$file $backupCWD #执行备份操作cd $backup_pathftp -i -n <<!open $host #登录FTP服务器user $UserName $Passwdif [ ! [ -d WEB-BACK/$path ]]; thenmkdir MYSQL-BACK/$path #如目录不存在则创建ficd MYSQL-BACK/$pathput $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!"

(责任编辑:张华文)