服务器下自动备份MySQL

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 Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" -uroot -paOulJpacChcUxVnc wbkchina> D:\backup\%File%

"C:\Program Files\WinRAR\WinRAR.exe" a -ibck -m5 -p12345 D:\backup\%TIME%.rar  D:\backup\%File%

forfiles -p "D:\backup" -s -m *.sql -c "cmd /c del @path"
forfiles -p "D:\backup" -s -m *.rar -d -3 -c "cmd /c del @path"

@echo on

 

 

 

posted @ 2016-06-01 14:20  Adtuu  阅读(271)  评论(0编辑  收藏  举报