windows定期清理日志
第一版:bad
@echo off
:: ======删除目录文件夹及其子文件夹内后缀名为.bak 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.bak /d -7 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1<nul
if %errorlevel% == "1" goto:A
:A
:: ======删除目录文件夹及其子文件夹内后缀名为.diff 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.diff /d -7 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1<nul
if %errorlevel% == "1" goto:B
:B
:: ======删除目录文件夹及其子文件夹内后缀名为.trn 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.trn /d -7 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1<nul
if %errorlevel% == "1"
exit
V2增强改进版:
@echo off
echo ***************************************************************************************
echo Get Current Time!!
echo ***************************************************************************************
chcp 936
set NOW_TIME_HH=%time:~0,2%
if "%NOW_TIME_HH%" lss "10" (set NOW_TIME_HH=0%time:~1,1%) else (set NOW_TIME_HH=%time:~0,2%)
set NOW_TIME=%date:~0,4%-%date:~5,2%-%date:~8,2%_%NOW_TIME_HH%-%time:~3,2%-%time:~6,2%
echo Current Time:%NOW_TIME%
:A
:: ======删除目录文件夹及其子文件夹内后缀名为.bak 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.bak /d -6 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1
if not %errorlevel% == 0 (goto bak)
:B
:: ======删除目录文件夹及其子文件夹内后缀名为.diff 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.diff /d -6 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1
if not %errorlevel% == 0 (goto diff)
:C
:: ======删除目录文件夹及其子文件夹内后缀名为.trn 且 7天之前的文件。======
forfiles /p "G:\DBBak" /s /m *.trn /d -6 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1
if not %errorlevel% == 0 (goto trn) else (goto success)
:bak
echo %NOW_TIME% bak cleanup failed >> G:\failed.log
goto:B
:diff
echo %NOW_TIME% diff cleanup failed >> G:\failed.log
goto:C
:trn
echo %NOW_TIME% trn cleanup failed >> G:\failed.log
goto:failed
:failed
echo *************************************************************************************** >> G:\failed.log
echo %NOW_TIME% clean backup failed >> G:\failed.log
echo *************************************************************************************** >> G:\failed.log
exit 55
:success
echo *************************************************************************************** >> G:\success.log
echo %NOW_TIME% clean backup success >> G:\success.log
echo *************************************************************************************** >> G:\success.log
exit 0
SQL server审计日志清理脚本
@echo off
echo ***************************************************************************************
echo Get Current Time!!
echo ***************************************************************************************
chcp 936
set NOW_TIME_HH=%time:~0,2%
if "%NOW_TIME_HH%" lss "10" (set NOW_TIME_HH=0%time:~1,1%) else (set NOW_TIME_HH=%time:~0,2%)
set NOW_TIME=%date:~0,4%-%date:~5,2%-%date:~8,2%_%NOW_TIME_HH%-%time:~3,2%-%time:~6,2%
echo Current Time:%NOW_TIME%
forfiles /p "F:\sqlaudits\dbaudits" /s /m *.sqlaudit /d -5 /c "cmd /c del @path" >> D:\DBBak\deletefile.txt 2>&1
if not %errorlevel% == 0 (goto failed) else (goto success)
:failed
echo %NOW_TIME% audit files cleanup failed >> F:\audit.log
exit 5
:success
echo %NOW_TIME% audit files cleanup success >> F:\audit.log
exit 0