Quick solution for archiving logs to an EBS volume as a Windows Scheduled Task

Contents of LS.ps1
—–
#Must change policy for Windows to allow the script to run, Run the following powershell command without hashtag
#Set-ExecutionPolicy RemoteSigned

$LogDir = “C:\inetpub\logs\wmsvc\W3SVC1”
$ArchiveDir = “D:\logarchive”
$Olderthan = 7

##Copy Files older than 7 days to Archive Directory
robocopy $LogDir $ArchiveDir /move /e /minage:$Olderthan
##Compress each Log file in the directory into a zip file
dir $ArchiveDir\*.log | ForEach-Object { & “C:\Program Files\7-Zip\7z.exe” a -tzip ($_.Name+”.zip”) $_.Name }
##Need to add code to validate logs were compressed before deleting, delete uncompressed Log Files.
del $ArchiveDir\*.log

——

1. Create a Log archive Volume in AWS
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html
2. Attach Volume to Instance
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
3.Make the Volume Available for Use
http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ebs-using-volumes.html#using-ebs-volume-windows
4.Create a Scheduled Task for the LogArchiving Powershell Script.
https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

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