Skip to content

Instantly share code, notes, and snippets.

@jstrassburg
Created March 25, 2014 14:20
Show Gist options
  • Save jstrassburg/9762804 to your computer and use it in GitHub Desktop.
Save jstrassburg/9762804 to your computer and use it in GitHub Desktop.
# 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