标签:
把下面脚本添加到服务器计划任务中去,设置为每天执行即可,文件备份路径即为脚本所在路径,必须安装压缩文件
@echo off
rem 计算指定天数之前的日期,用于后面删除指定天数的数据
set DaysAgo=7
set/a year=1
rem 假设系统日期的格式为yyyy-mm-dd
call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDays
set /a PassDays-=%DaysAgo%
call :DaysToDate %PassDays% DstYear DstMonth DstDay
set DstDate=%DstYear%-%DstMonth%-%DstDay%
echo 备份%date%的数据
rem 本处需要设置用户名,密码,TNSNAME,DMP文件名,日志文件名
exp menuDB/menuDB@ORCL file=%~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.dmp log=%~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.log
echo "压缩 %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.dmp %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.log数据"
rem 选择压缩软件的安装目录 进行压缩
"C:\Program Files\WinRAR\WinRAR.exe" a %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.rar %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.dmp %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.log
echo 删除%~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2% dmp log 文件
rem 删除当天备份的dmp 和log文件
del %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.dmp
del %~dp0menuDB%date:~0,4%%date:~5,2%%date:~8,2%.log
echo 删除%DaysAgo%天前也就是%DstDate%的备份
rem 本处参照上面设定的DMP文件名和日志文件名,对指定天数之前的数据进行删除
del %~dp0menuDB%DstDate:~0,4%%DstDate:~5,2%%DstDate:~8,2%.rar
goto :eof
:DateToDays %yy% %mm% %dd% days
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
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 %4=%j%&goto :EOF
:DaysToDate %days% yy mm dd
setlocal ENABLEEXTENSIONS
set /a a=%1+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%&set %3=%mm%&set %4=%dd%&goto :EOF
数据库自动备份压缩脚本(备份最近七天,七天之前自动删除,只保留rar文件)
标签:
原文地址:http://www.cnblogs.com/qishiguilai/p/4270715.html