Posted On March 31, 2019

Dump Folder Archival Script

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Dump Folder Archival Script
Requirements:
- Zip any .BAK files that are over 7 days
- Delete any zip files that have been generated 12 months ago

Solution:
- Install 7zip: https://7-zip.org/download.html
- Add C:\Program Files\7-Zip into Windows environmental path
- Create this batch file :
-------------------- cleanupbackups.bat ---------------------
@echo off
:: set folder path
set dump_path="D:\backups"

:: set min age of files and folders to compress
set max_days="7"

:: set max days of archive to maintain
:: set max_archived="358"

:: compress files from %dump_path%
forfiles -s -p %dump_path% -m *.bak -d -%max_days% -c "cmd /c 7z a -t7z @path.7z @path -ms -mmt"

:: remove files from %dump_path%
set dump_path="D:\backups"
forfiles -s -p %dump_path% -m *.bak -d -%max_days% -c "cmd /c del /q @path"

:: prune archive
set dump_path="D:\backups"
forfiles -s -p %dump_path% -m *.7z -d -%max_archiveds% -c "cmd /c del /q @path"

------------------------------------------------------------------
- Set Scheduled Tasks to call this batch file daily at 12:00 AM

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Microsoft Exchange Active Directory Integration

Assuming that Exchange is already set and in production, it's often advisable to record its…

Domain Name Records Overview: A-record, MX, DKIM, SPF, SRV

A RECORD (A-host): - What: address record (A-record) specifies the IP address(es) of a given…

PowerShell: Windows Get-EventLog vs Get-WinEvent

Get-Eventlog is the legacy Windows log querying command. Its advanced filtering is limited. Whereas Get-WinEvent,…