crontab job设置:
1 2 |
30 01 * * * /root/copy_db_files.sh 30 03 * * * /root/scp_to_backupserver.sh |
copy_db_files.sh脚本
1 2 3 4 |
#/bin/bash cp -rf /usr/local/mysql ./ tar jcvf mysql_$(date +"%Y%m%d").tar.bz2 ./mysql rm -rf ./mysql |
scp_to_backupserver.sh脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#!/usr/bin/expect -f #define variable. set passwd "yourpassword" set mydate [exec date "+%Y%m%d"] #use scp spawn scp ./mysql_$mydate.tar.bz2 sap@10.10.10.223:/database/mysql/ #intput password & execute upper command. expect { "密码:" { send "$passwd\n" } "pass" { send "$passwd\n" } "yes/no" { sleep 5 send_user "send yes" send "yes\n" } eof { sleep 5 send_user "eof\n" } } #never timeout until upper command completed! set timeout -1 send "exit\r" expect eof |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/2027.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
评论列表(2条)
shell脚本注意两点:
1.#!/usr/bin/expect -f 要首行顶格写。
2.set timeout -1 否则内容传到一半就断开连接了。
直接拷贝数据库进行备份的方法:
1.关闭掉MySQL
2.cp/scp到目标路径
3.确保权限正确
4.启动mysql