rem #########################30天前日期获取####################
call :Date2Day %date:~0,10% sdays
set /a sdays-=30
call :Day2Date %sdays% difdate
set "yy=%difdate:~0,4%"
set "mm=%difdate:~5,2%"
set "dd=%difdate:~8,2%"
set "datethirtyago=%yy%%mm%%dd%"
#windows 下批处理文件。 把此批处理文件添加至计划任务,每天5点执行。
rem This is a daily auto exp©&delete dmp script.
set nowdate=%date:~,10%
rem define the dmp path
set copydmppath=f:\sim_event_historydatas\ # f:\sim_event_historydatas\路径为ftp映射至本地路径,注意创建logs文件夹
rem define logfile
set logFile=%copydmppath%\logs\"autodelete%nowdate:/=-%.log"
#rem 导出分区数据,请根据SID情况修改脚本
set ORACLE_SID=XXX
expdp sim/password directory=dump_dir dumpfile="sim_event%datethirtyago:/=-%.dmp" tables=(sim_event:P%datethirtyago%) logfile="expdp_sim_event%datethirtyago:/=-%.log"
#rem 复制dmp&log文件至ftp服务器
echo .............................. %nowdate% .............................. >> %logFile%
echo copy sim_event_dmp ...... >> %logFile%
copy D:\DUMP_DIR\"sim_event%nowdate:/=-%.dmp" %copydmppath% >> %logFile%
#rem 删除3日前dmp&log文件
echo deleting old sim_event_historydata before 3 days...... >> %logFile%
echo deleting old sim_event_historydata before 3 days......
forfiles /D -3 /P D:\DUMP_DIR\ /M * /C "cmd /c del /Q /S @file" >> %logFile%
rem ###############生成StartTime需要调用的函数###########
:Date2Day
setlocal ENABLEEXTENSIONS
for /f "tokens=1-3 delims=/-, " %%a in ('echo/%1') do (
set yy=%%a & set mm=%%b & set dd=%%c
)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %2=%j%&goto :EOF
:Day2Date
setlocal ENABLEEXTENSIONS
set /a i=%1,a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %2=%yy%-%mm%-%dd%&goto :EOF
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22051233/viewspace-773660/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22051233/viewspace-773660/