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: http://www.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:\Trav11\TravBack"

:: 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:\Trav11\TravBack"
forfiles -s -p %dump_path% -m *.bak -d -%max_days% -c "cmd /c del /q @path"

:: prune archive
set dump_path="D:\Trav11\TravBack"
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 *