定时备份mysql数据库的批处理

发布时间:2020-10-09编辑:脚本学堂
定时备份mysql数据库的批处理

定时备份mysql/ target=_blank class=infotextkey>mysql数据库批处理代码,保存为backup_mysql.bat,运行即可。
 

复制代码 代码如下:
@echo off
set txt1=%date:~0,4%
::当前年
set txt2=%date:~5,2%
::当前月
set txt3=%date:~8,2%
::当前日
set txt4=%time:~0,2%
::当前小时
set txt5=%time:~3,2%
::当前分钟
set txt6=%time:~6,2%
::当前秒
set date=%txt1%%txt2%%txt3%
set time=%txt4%%txt5%%txt6%
echo --------------------------------------------------
echo -------------正在执行Mysql数据库备份--------------
echo --------------------------------------------------
echo ...
echo ...
echo 导出Database...
if exist %date%.sql del %date%.sql
c:Progr*mysqlbinmysqldump --add-drop-table -c -u root -p-h localhost dbname >e:%date%.sql
echo ...
echo ...
if exist dump%date%.7z del dump%date%.7z
echo 压缩文件...
7za.exe a -t7z dump%date%.7z %date%.sql -mx9
echo ...
echo ...
echo 删除临时文件
del %date%.sql
echo ...
echo ...
echo 备份完成!
pause