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: Creating Active Directory Accounts from CSV File

# User-input Variables $csvFile='C:\Users\rambo\Desktop\newUsers-finalized.csv' $newOu='CN=Users,DC=kimconnect,DC=com' $newCompany='KimConnect.com' $logFile="c:\temp\createActiveDirectoryAccounts-$(get-date -f yyyy-mm-dd-hh-mm-ss).txt" function createActiveDirectoryAccounts{ param( $csvFile, $newOu, $newCompany,…

PowerShell: Create, Edit User Accounts Basing on CSV File

# Create New Users: defined as names in CSV that does not exist in Existing…

Quick 1-liner Generate List of Active Directory users

# Discover domain controller:echo %LOGONSERVER%# Display Users:dsquery user -limit 0 | dsget user -display -dept…