http://skzr-org.javaeye.com/blog/811491
目标:
- 定时导出:利用计划任务
- 自动压缩:使用命令行的rar
- 自动按月存储:利用cmd
代码:
- @echo一定要进入指定路径,否则运行不正常
- @setbk_path=G:/Database_bak
- @setrar_path=d:/WinRAR
- @setowner=erp_beijing_exp
- @setuserid=%owner%/erp_beijing_exp@dbsvr
- @echoon
- @CLS
- @echo欢迎使用自动导库程序
- @echo开始执行
- @echo进入目录:%bk_path%
- @%bk_path:~0,2%
- @cd%bk_path%
- cd
- setTHE_MONTH=%DATE:~0,4%-%DATE:~5,2%
- setTHE_DATE=%THE_MONTH%-%DATE:~8,2%
- echo%THE_DATE%
- setMY_HOUR=%time:~0,2%
- if"%time:~0,1%"==""setMY_HOUR=0%time:~1,1%
- SETMY_DATE=%THE_DATE%_%MY_HOUR%-%TIME:~3,2%-%TIME:~6,2%
- @echo当前时间%THE_DATE%
- @setfilename=%MY_DATE%_%username%
- exp.exeuserid="%userid%"owner=%owner%file=%filename%.dmplog=%filename%-exp.log
- "%rar_path%/rar"a-k-t-s-m5-mc63:128t+-mdg-df%filename%.rar%filename%*.*
- MKDIR%bk_path%/%THE_MONTH%
- MOVE%bk_path%/*%THE_DATE%*.*%bk_path%/%THE_MONTH%
- exit
@echo 一定要进入指定路径,否则运行不正常 @set bk_path=G:/Database_bak @set rar_path=d:/WinRAR @set owner=erp_beijing_exp @set userid=%owner%/erp_beijing_exp@dbsvr @echo on @CLS @echo 欢迎使用自动导库程序 @echo 开始执行 @echo 进入目录: %bk_path% @%bk_path:~0,2% @cd %bk_path% cd set THE_MONTH=%DATE:~0,4%-%DATE:~5,2% set THE_DATE=%THE_MONTH%-%DATE:~8,2% echo %THE_DATE% set MY_HOUR=%time:~0,2% if "%time:~0,1%"==" " set MY_HOUR=0%time:~1,1% SET MY_DATE=%THE_DATE%_%MY_HOUR%-%TIME:~3,2%-%TIME:~6,2% @echo 当前时间%THE_DATE% @set filename=%MY_DATE%_%username% exp.exe userid="%userid%" owner=%owner% file=%filename%.dmp log=%filename%-exp.log "%rar_path%/rar" a -k -t -s -m5 -mc63:128t+ -mdg -df %filename%.rar %filename%*.* MKDIR %bk_path%/%THE_MONTH% MOVE %bk_path%/*%THE_DATE%*.* %bk_path%/%THE_MONTH% exit
遇到的问题和解决:
- 文件名中:小时在10点之前为“ X”有个空格导致文件名出问题,解决set MY_HOUR=%time:~0,2%
- if"%time:~0,1%"==""setMY_HOUR=0%time:~1,1%
if "%time:~0,1%"==" " set MY_HOUR=0%time:~1,1%