一、本地和异地ftp传输备份脚本
'本地采用12小时一备同时上传异地
'文件备份目录创建auto_bak,我放在/usr/local/目录下
[root@localhost local]#mkdir auto_bak
[root@localhost local]#cd auto_bak
'编写备份脚本
[root@localhost auto_bak]#vi auto_bak_db.sh
#!/bin/sh
#delete old file
rm -rf /usr/local/auto_bak/dbname*
#backup the datebase file to
/usr/local/mysql/bin/mysqldump -u sa 123456 dbname >/usr/local/auto_bak/dbname.sql
#ftp the file to 192.168.0.11
#login in Ftp server and transfer the file
ftp -i -n < open 192.168.0.11
user bak 123456
#turn to local directory
lcd /usr/local/auto_bak/
#transfer the file and add time lable
put /usr/local/auto_bak/dbname.sql dbname`date -d today +"20%y-%m-%d"~"%H:%M"`.sql
quit
end
'添加权限
[root@localhost auto_bak]#chmod +x auto_bak_db.sh
二、使用crontab定时执行auto_bak_db.sh
[root@localhost local]#crontab -u root -e
#每12小时备份一次,并记录到日志
0 */12 * * * /usr/local/auto_bak/auto_bak_db.sh 1>/usr/local/auto_bak/auto_bak_db.log 2>&1
说明:后面所加的" 1>/usr/local/auto_bak/auto_bak_db.log 2>&1 " 产生的日志可以作为问题查找的参考。
阅读(1784) | 评论(0) | 转发(0) |