自动备份数据库,并且删除2月前的备份,并自动上传至gitee,中间sleep 2秒种。
编写 mysqlBack.sh
#!/bin/sh time1=$(date "+%Y%m%d-%H%M%S") mysqldump -uroot -pxxxxxx zhouyi2>git/zhouyi2_$time1.sql // -p是密码
编写 mysqlGit.sh
#!/bin/sh time1=$(date -d '-2 month' "+%Y%m%d") time2=$(date "+%Y%m%d") cd /root/git git add zhouyi2* #echo $time1 sleep 2 git rm zhouyi2_$time1* sleep 2 git commit -m "sql $time2" sleep 2 git push origin master
编写crontab -e
0 6 * * * /root/mysqlBackup.sh 10 6 * * * /root/mysqlGit.sh