MYSQL自动备份脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL自动备份脚本相关的知识,希望对你有一定的参考价值。
mysqldump() { echo “开始进行 $mysql_dbname1 $mysql_dbname2 备份…” if [ -d "${backdir}/${date}" ];then echo “Mysql Database dir already exists.” exit 1 else mkdir -p ${backdir}/${date} echo “开始备份 ${mysql_dbname1} …” /usr/bin/mysqldump -u $mysql_user -p$mysql_passwd $mysql_dbname1 > ${backdir}/${date}/${mysql_dbname1}.sql sleep 1 if [ $? -eq 0 ];then echo “${mysql_dbname1} backup Successful!” else echo “${mysql_dbname1} backup failed!” exit 1 fi echo “开始备份 ${mysql_dbname2} …” /usr/bin/mysqldump -u $mysql_user -p$mysql_passwd $mysql_dbname2 > ${backdir}/${date}/${mysql_dbname2}.sql sleep 1 if [ $? -eq 0 ];then echo “${mysql_dbname2} backup Successful!” else echo “${mysql_dbname2} backup failed!” exit 1 fi fi return $? } backup() { mysqldump if [ $? -eq 0 ];then echo “${mysql_dbname1} and ${mysql_dbname2} 备份成功!” fi } backup PYTHON #写入crontab,每日00:01进行自动备份。 [[email protected] ~]# cat /etc/crton cat: /etc/crton: No such file or directory [[email protected] ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 00 01 * * * * root /bin/bash /backup/backup.sh
本文出自 “少犟” 博客,请务必保留此出处http://xushaojie.blog.51cto.com/6205370/1783609
以上是关于MYSQL自动备份脚本的主要内容,如果未能解决你的问题,请参考以下文章