1. 在dos命令行下运行数据库全备份批处理脚本full_backup.bat
因为mysqldump是mysql自带的exe程序,执行mysqldump时务必到mysqlbin 目录下运行脚本或双击full_backup.bat(在bat中要cd到mysql的bin目录下),其中full_backup.bat里面的mysqldump导出路径,指定导出服务器IP,数据库名称,字符集,用户名,密码需要根据具体情况修改
2. 全备份批处理脚本full_bakcup.bat如下:
@echo off
echo ======================
echo backup discuz databae
@REM 取出当前时间
for /f "tokens=1-3 delims=- " %%a in ('date/t') do (
set yy=%%a
set mm=%%b
set dd=%%c
)
for /f "tokens=1-3 delims=: " %%d in ('time/t') do (
set hh=%%d
set mi=%%e
)
@REM 设置mysqldump导出路径,指定导出服务器IP,数据库名称,字符集,用户名,密码等
set backupdir=E:\MySQL备份\mysql_backup
SET host=172.16.4.41
SET database1=discuz
SET character=--default-character-set
SET charactername=gb2312
SET mysqlpassword=discuz
SET mysqluser=discuz
SET logdir=E:\MySQL备份\mysql_backup
SET filename1=%database1%%yy%%mm%%dd%%hh%%mi%%ss%.sql
SET start=%date% - %time%: Database Backup of %database% Started
@REM Start Logging
ECHO %start%
ECHO %start% >> %logdir%\mysqlbackup.log
@REM dump database. This is all one line
mysqldump -h%host% -u %mysqluser% -p%mysqlpassword% %character%=%charactername% %database1% > %backupdir%\%filename1%
if not exist %backupdir%\%filename1% goto FAIL_DUMP
@REM All is well
GOTO SUCCESS
:FAIL_DUMP
SET message=%date% - %time%: Database Dump of %database1% Failed
GOTO END
:FAIL_MOVE
SET message=%date% - %time%: Backup Move of %database% Failed
GOTO END
:SUCCESS
SET message=%date% - %time%: Backup of %database% Completed Succesfully
GOTO END
:END
ECHO %message%
ECHO %message% >> %logdir%\mysqlbackup.log
ECHO ===============================================================================
ECHO
3. 加入WINDOWS执行计划执行每日备份
在“控制面板”=》“执行计划”=》“添加执行计划”下添加执行计划,我选择每日执行