Linux下 service crond restart */10 * * * * /home/mysqlbackup.sh >/home/runssh.log backup.sh #bin/bash source ~/.bash_profile LANG=en_US.UTF-8 cd /home/backup/gch Now=$(date +"%Y%m%d%H%M%S") File=backup-$Now.sql #最低优先级执行 /bin/nice -n 19 /opt/lampp/bin/mysqldump -uroot -ptest db > $File #压缩文件 /bin/nice -n 19 tar -zPcf $File.tar.gz $File #删除sql文件 删除5天前的文件 rm -rf *.sql find /home/backup -mtime +5 -name "*.sql.tar.gz" -exec rm -rf {} ; #自动备份到SVN服务器 svn up svn add * svn commit -m 'backup' echo success
Windows下backupMySQL.bat @echo off set h=%TIME:~0,2% set h=%h: =0% set "Time=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%%h%%TIME:~3,2%%TIME:~6,2%" set "File=backup_%Time%.sql" "C:Program FilesMySQLMySQL Server 5.5inmysqldump.exe" -uroot -paOulJpacChcUxVnc wbkchina> D:ackup\%File% "C:Program FilesWinRARWinRAR.exe" a -ibck -m5 -p12345 D:ackup\%TIME%.rar D:ackup\%File% forfiles -p "D:ackup" -s -m *.sql -c "cmd /c del @path" forfiles -p "D:ackup" -s -m *.rar -d -3 -c "cmd /c del @path" @echo on