Created
March 25, 2014 14:20
-
-
Save jstrassburg/9762804 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rename *.log files to be prefixed with YYYYmmdd- and upload to an S3 bucket | |
# Author: James Strassburg <[email protected]> | |
$bucketName = "myS3bucket" | |
$sourceLogs = "\\myfileserver\mylogdir" | |
$logFilter = "*.log" | |
$date = Get-Date -UFormat "%Y%m%d" | |
$bucket = Get-S3Bucket -BucketName $bucketName | |
if ($bucket -eq $null) | |
{ | |
Write-Host "Creating S3 bucket $bucketName..." | |
New-S3Bucket $bucketName | |
} | |
Get-ChildItem -path $sourceLogs -Filter $logFilter | ForEach-Object { | |
$name = $_.Name | |
Rename-Item -path $_.FullName -newName "$date-$name" | |
} | |
Get-ChildItem -path $sourceLogs -Filter $logFilter | ForEach-Object { | |
Write-S3Object -BucketName $bucketName -Key $_.Name -File $_.FullName | |
Remove-Item $_.FullName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment