欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用bat实现定时执行任务的批处理文件

程序员文章站 2022-03-07 21:15:49
@echo off set txt1=%date:~0,4% ::当前年 set txt2=%date:~5,2% ::当前月 set&nbs...
@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*\mysql\bin\mysqldump --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