Mysqldump () {echo "start $mysql _dbname1 $mysql _dbname2 backup ..." if [ -d "${backdir" }/${date} " ];thenecho " Mysql database dir already exists. " exit 1elsemkdir -p ${backdir}/${date}echo "Start Backup ${mysql_dbname1} ..."/usr/bin/ mysqldump -u $mysql _user -p$mysql_passwd $mysql _dbname1 > ${backdir}/${date}/ ${mysql_dbname1}.sqlsleep 1if [ $? -eq 0 ];thenecho "${mysql_dbname1} backup successful! " elseecho "${mysql_dbname1} backup failed!" exit 1fiecho "Start Backup ${mysql_dbname2} ..."/usr/bin/mysqldump -u $mysql _user -p$ mysql_passwd $mysql _dbname2 > ${backdir}/${date}/${mysql_dbname2}.sqlsleep 1if [ $? -eq 0 ];thenecho "${mysql_dbname2} backup successful!" elseecho "${mysql_dbname2} backup failed!" exit 1fifireturn $?} Backup () {mysqldumpif [ $? -eq 0 ];thenecho "${mysql_dbname1} and ${ mysql_dbname2} Backup succeeded! "Fi}backuppython# writes to Crontab, which is automatically backed up 00:01 daily. [[Email protected] ~]# cat /etc/crtoncat: /etc/crton: no such file or directory[[email protected] ~]# cat /etc/crontab shell=/bin/bashpath=/ sbin:/bin:/usr/sbin:/usr/binmailto=roothome=/# for details see man 4 crontabs#  EXAMPLE OF JOB DEFINITION:#&NBSP:---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .--------- - day of month (1 - 31) # | | | .------- month (1 - 12) or jan,feb,mar,apr ...# | | |   | &NBSP---- day of week (0 - 6) (sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | | | |# * * * * * user-name command to be executed00 01 * * * * root /bin/bash /backup/backup.sh
This article is from the "less stubborn" blog, please be sure to keep this source http://xushaojie.blog.51cto.com/6205370/1783609
MySQL Automatic backup script