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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律