Skip to main content

Archive log files

:: Daily archive log files older than n days
:: Created date: YYYYMMDD
:: Created by:
:: Last modified: YYYYMMDD
:: Last modified by:
:: History:
::

SET DIRLOG=D:\_scripts\Logs\
SET ziptype=gz
SET days=1

:: archive files
ECHO "Begin" >> %dirlog%daily-archive-logfiles.txt
DATE /T >> %dirlog%daily-archive-logfiles.txt
TIME /T >> %dirlog%daily-archive-logfiles.txt
FORFILES /P %DIRLOG% /S /M *.log /D -%days% /C "cmd /c ^0x22C:\Program^ Files\7-Zip\7z.exe^0x22 a -tgzip @path.gz @path" >> %dirlog%daily-archive-logfiles.txt
ECHO "Finished" >> %dirlog%daily-archive-logfiles.txt
DATE /T >> %dirlog%daily-archive-logfiles.txt
TIME /T >> %dirlog%daily-archive-logfiles.txt
:: END of script

Popular posts from this blog

Delete files older than 365 days

I must delete IIS *.log files in  older than 365 days. D:\Logs | -W3SVC1 -W3SVC2 -... -W3SVC33 daily-delete-logfiles-older-than-365-days.cmd :: Daily delete log files older than 365 days :: Created on: 20161120 :: Created by: :: Last modified on: :: Last modified by: :: History: SET DIRLOG=E:\_scripts\Logs\ :: Echo @path to test first :: FORFILES /P D:\Logs /S /M *.log /D -365 /C "cmd /c echo @path @fdate" :: Delete files ECHO "Begin" >> %dirlog%daily-delete-logfiles.log DATE /T >> %dirlog%daily-delete-logfiles.log TIME /T >> %dirlog%daily-delete-logfiles.log FORFILES /P D:\Logs /S /M *.log /D -365 /C "cmd /c del @path" >> %dirlog%daily-delete-logfiles.log ECHO "Finished" >> %dirlog%daily-delete-logfiles.log DATE /T >> %dirlog%daily-delete-logfiles.log TIME /T >> %dirlog%daily-delete-logfiles.log :: END of script /P : Path to folder /S: recurse into subdirectories /M *.l...

PluralSight: Free Courses

Register free account at https://app.pluralsight.com to explore these free courses.

Ping group on Windows with FOR command

Notes from daily work situation.