Add the following script to the server scheduled task, set to execute daily, the file backup path is the path of the script, you must install the compressed file
@echo off
REM Calculates a date that precedes a specified number of days and is used to delete data for a specified number of days
Set daysago=7
set/a year=1
REM assumes that the format of the system date is YYYY-MM-DD
Call:D atetodays%date:~0,4%%date:~5,2%%date:~8,2% passdays
set/a passdays-=%daysago%
Call:D aystodate%passdays% dstyear dstmonth dstday
Set dstdate=%dstyear%-%dstmonth%-%dstday%
echo back up the%date% data
REM We need to set user name, password, tnsname,dmp file name, log file name
Exp Menudb/[email protected] 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 "Compress%~dp0menudb%date:~0,4%%date:~5,2%%date:~8,2%.dmp%~dp0menudb%date:~0,4%%date:~5,2%%date:~8,2%.log data"
REM Select the compression software installation directory to compress
"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 Delete%~dp0menudb%date:~0,4%%date:~5,2%%date:~8,2% dmp log file
REM Delete dmp and log files backed up on the same day
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 Delete%daysago% days ago that is%dstdate% backup
REM to delete data before the specified number of days, referring to the DMP file name and log file name set above
Del%~dp0menudb%dstdate:~0,4%%dstdate:~5,2%%dstdate:~8,2%.rar
Goto:eof
:D atetodays%yy%%mm%%dd% days
Setlocal enableextensions
Set Yy=%1&set Mm=%2&set dd=%3
If 1%yy% LSS 1%yy% LSS (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
:D aystodate%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 set mm=0%mm%) & (if%dd% LSS set dd=0%dd%)
Endlocal&set%2=%yy%&set%3=%mm%&set%4=%dd%&goto:eof
Database automatic backup compression script (backup last seven days, seven days ago automatically deleted, only RAR files are preserved)