mysql数据库备份(含异地备份功能)
时间:2006-11-15 来源:yourwcd
@echo off
cd C:\iSignatureServer\mysql\
C: rem ******************************************************************************************************
rem 功能描述:WIN2K下MYSQL数据库自动备份
rem 书写人:WCD
rem 书写日期:2006-09-27
rem 详细说明:
rem (1)、如果要启用异地备份,请设置remote_bak=1并设置相应的远程机器名称和共享的目录。(注意共享的目录一定
rem 要有写的权限)
rem (2)、因为本备份是采用日期作为备份文件的名称。所以对日期格式有要求。请将日期格式改: yyyy-MM-dd
rem 时间格式改为:HH:mm:ss
rem ****************************************************************************************************** for /f "tokens=1-10 delims=- " %%a in ('DATE /T') do set Date=%%a-%%b-%%c
set myDate=%Date:~-10% echo **** 数据库自动备份开始 ****
rem 设置remote_bak=1启动异地备份 设置为0不起用异地备份 set remote_bak=0 rem 异地计算机设置的共享目录,(注意:必须是完全共享,即有写的权限)
set remote_path= rem 本地备份路径
set local_path=c: rem 判断mysql服务是否启动,未启动先启动
netstat -na | (find "0.0.0.0:3306" & find "LISTENING")>server.log
fc server.log temp.log
if %errorlevel%==0 goto backup
echo ***** 未启动MYSQL服务,开始启动MYSQL服务(日期:%myDate%时间:%time:~0,20%) *****
rem bin\mysqld-nt --defaults-file="my.ini"
start MYSQL.BAT
echo ***** 启动MYSQL服务成功(日期:%myDate%时间:%time:~0,20%) ***** :backup if not exist %local_path%\%myDate% md %local_path%\%myDate%
echo **** 开始本地备份(日期:%myDate%时间:%time:~0,20%) ****
if %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >%local_path%\%myDate%\%time:~0,2%%time:~3,2%%time:~6,2%.sql
if not %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >%local_path%\%myDate%\%time:~1,1%%time:~3,2%%time:~6,2%.sql
echo **** 本地备份完成(日期:%myDate%时间:%time:~0,20%) **** :remote_backup
if %remote_bak%==0 goto end rem if not exist z: net use z: %remote_machine%\%remote_path% ""/user:"guest"
if not exist z: net use z: %remote_path%
if not exist z:\%myDate% md z:\%myDate%
echo **** 开始异地备份(日期:%myDate%时间:%time:~0,20%) ****
if %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >z:\%myDate%\%time:~0,2%%time:~3,2%%time:~6,2%.sql
if not %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >z:\%myDate%\%time:~1,1%%time:~3,2%%time:~6,2%.sql
echo **** 异地备份完成(日期:%myDate%时间:%time:~0,20%) ****
net use z: /delete :end
del server.log
echo **** 数据库自动备份结束(日期:%myDate%时间:%time:~0,20%) ****
cd C:\iSignatureServer\mysql\
C: rem ******************************************************************************************************
rem 功能描述:WIN2K下MYSQL数据库自动备份
rem 书写人:WCD
rem 书写日期:2006-09-27
rem 详细说明:
rem (1)、如果要启用异地备份,请设置remote_bak=1并设置相应的远程机器名称和共享的目录。(注意共享的目录一定
rem 要有写的权限)
rem (2)、因为本备份是采用日期作为备份文件的名称。所以对日期格式有要求。请将日期格式改: yyyy-MM-dd
rem 时间格式改为:HH:mm:ss
rem ****************************************************************************************************** for /f "tokens=1-10 delims=- " %%a in ('DATE /T') do set Date=%%a-%%b-%%c
set myDate=%Date:~-10% echo **** 数据库自动备份开始 ****
rem 设置remote_bak=1启动异地备份 设置为0不起用异地备份 set remote_bak=0 rem 异地计算机设置的共享目录,(注意:必须是完全共享,即有写的权限)
set remote_path= rem 本地备份路径
set local_path=c: rem 判断mysql服务是否启动,未启动先启动
netstat -na | (find "0.0.0.0:3306" & find "LISTENING")>server.log
fc server.log temp.log
if %errorlevel%==0 goto backup
echo ***** 未启动MYSQL服务,开始启动MYSQL服务(日期:%myDate%时间:%time:~0,20%) *****
rem bin\mysqld-nt --defaults-file="my.ini"
start MYSQL.BAT
echo ***** 启动MYSQL服务成功(日期:%myDate%时间:%time:~0,20%) ***** :backup if not exist %local_path%\%myDate% md %local_path%\%myDate%
echo **** 开始本地备份(日期:%myDate%时间:%time:~0,20%) ****
if %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >%local_path%\%myDate%\%time:~0,2%%time:~3,2%%time:~6,2%.sql
if not %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >%local_path%\%myDate%\%time:~1,1%%time:~3,2%%time:~6,2%.sql
echo **** 本地备份完成(日期:%myDate%时间:%time:~0,20%) **** :remote_backup
if %remote_bak%==0 goto end rem if not exist z: net use z: %remote_machine%\%remote_path% ""/user:"guest"
if not exist z: net use z: %remote_path%
if not exist z:\%myDate% md z:\%myDate%
echo **** 开始异地备份(日期:%myDate%时间:%time:~0,20%) ****
if %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >z:\%myDate%\%time:~0,2%%time:~3,2%%time:~6,2%.sql
if not %time:~0,2% GEQ 10 bin\mysqldump --opt -u goldgrid --password=goldgrid-iSignature isignaturekey >z:\%myDate%\%time:~1,1%%time:~3,2%%time:~6,2%.sql
echo **** 异地备份完成(日期:%myDate%时间:%time:~0,20%) ****
net use z: /delete :end
del server.log
echo **** 数据库自动备份结束(日期:%myDate%时间:%time:~0,20%) ****
相关阅读 更多 +