http://skzr-org.javaeye.com/blog/811491
Goal: Timed export: Use Scheduled tasks to automatically compress: using the command line RAR automatic monthly storage: using cmd
Code:
CMD code @echo must go to the specified path, otherwise it will run abnormally @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 Welcome to use the Automatic library program @echo Start execution @echo Access directory: %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 Current time%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
@echo must enter the specified path, otherwise it will not run properly
@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 Welcome to the automatic library
@echo start Execution
@ echo into directory:%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 Current Time%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
Problems encountered and resolved:
File name: The hour before 10 o'clock for "X" has a space to cause file name problems, solve the set my_hour=%time:~0,2% cmd code if "%time:~0,1%" "" Set my_hour=0%time:~1,1%
If "%time:~0,1%" = "" Set my_hour=0%time:~1,1%