您当前的位置: 站长圈 > 数据库技术

MySQL备份

来源:站长圈|0 作者:adminzzq 点击: 0
@ECHO OFF

CLS
Title MySQL Backup
ECHO ===============================================================================
ECHO                          MySQL Backup Script
ECHO     This script does the following
ECHO       -Backs up the specified database.
ECHO       -Compresses the backup.
ECHO       -Writes to a log file.
ECHO       -By: Redwolf.
ECHO ===============================================================================

@REM Date Configuration
for /f "tokens=1,2,3 delims=/- " %%i in ('echo %date%') do (
  set yy1=%%i
  set mm1=%%j
  set dd1=%%k)

@REM Date Configuration
for /f "tokens=1-4 delims=/ " %%a in ('date/t') do (
set dw=%%a
set mm=%%b
set dd=%%c
set yy=%%d
)

@REM Backup Configuration
SET servername=localhost
SET database=wygl
SET backupdir=d:\tool\MySQL\backup
SET mysqldir="d:\tool\MySQL\MySQL Server 5.1\bin"
SET mysqlpassword=root
SET mysqluser=root
SET logdir=d:\tool\MySQL\log
SET filename=%servername%.%database%.%yy%%mm%%dd%%dw%.sql
@rem  filename=%servername%.%database%.%yy1%-%mm1%-%dd1%.sql

 

@REM Start Logging
ECHO %start%
ECHO %start% >> %logdir%\mysqlbackup.log

@REM dump database. This is all one line
mysqldump -u%mysqluser% -p%mysqlpassword% -R %database%>%backupdir%\%filename%
if not exist %backupdir%\%filename% goto FAIL_DUMP

@REM All is well
GOTO SUCCESS

:FAIL_DUMP
SET message=%date% %time% : 数据库 %database% 备份失败!
GOTO END

:SUCCESS
SET message=%date% %time% : 数据库 %database% 备份成功!
GOTO END


:END
ECHO Programing writing logfile pleases wait...........
ECHO %message%
ECHO %message% >> %logdir%\mysqlbackup.log

rem ECHO. & pause