|
@goto Start
==============================================================
功能:
1、备份mysql中的数据库
2、数据最多保留8份,假如你每天做一个备份,则可以保留最近8天内的数据,你可以任意恢复
用法:backupmysql mysql_user_name mysql_password mysql_db save_path
批处理文件名 mysql的用户名 mysql的密码 要备份的数据库名 保存路径
注意事项:
1、保存路径必须是已经存在的路径且必须以\结尾,例:f:\backup\
2、不用指定保存文件名,程序自动以数据库名+备份时的年月日+.sql为文件为
3、一个备份例子:backupmysql root am1db dotproject c:\amp\mysql\bin\
4、数据库恢复:mysql -uroot -pam1db dotproject <dotproject20050805.sql
mysql -umysql的用户名 -pmysql的密码 要恢复的数据库名 管道符号< 备份数据库文件
版本:1.0
作者:Mr.Lee
创建日期:2005.08.05
:Start
::定义变量
@set username=%1
@set pwd=%2
@set databasename=%3
@set backuppath=%4
@if exist %backuppath%%databasename%.bak7 @del %backuppath%%databasename%.bak7
@if exist %backuppath%%databasename%.bak6 @ren %backuppath%%databasename%.bak6 %databasename%.bak7
@if exist %backuppath%%databasename%.bak5 @ren %backuppath%%databasename%.bak5 %databasename%.bak6
@if exist %backuppath%%databasename%.bak4 @ren %backuppath%%databasename%.bak4 %databasename%.bak5
@if exist %backuppath%%databasename%.bak3 @ren %backuppath%%databasename%.bak3 %databasename%.bak4
@if exist %backuppath%%databasename%.bak2 @ren %backuppath%%databasename%.bak2 %databasename%.bak3
@if exist %backuppath%%databasename%.bak1 @ren %backuppath%%databasename%.bak1 %databasename%.bak2
@if exist %backuppath%%databasename%.sql @ren %backuppath%%databasename%.sql %databasename%.bak1
@rem @for /f "tokens=1,2,3 delims=:." %%i in ("%time%") do @set /a hms=%%i%%j%%k
@rem @for /f "tokens=1,2,3 delims=- " %%i in ("%date%") do @set /a ymd=%%i%%j%%k
@set bakfilename=%backuppath%%databasename%.sql
@mysqldump --opt -u %username% -p%pwd% %databasename%>%bakfilename% |
|