-
-
Save rterbush/b08c2eb429162d40d77f 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
Param( | |
[Parameter(Mandatory=$True)] | |
[string]$Bucket, | |
[Parameter(Mandatory=$True)] | |
[string]$Prefix, | |
[Parameter(Mandatory=$True)] | |
[string]$ARN | |
) | |
$CompName = $env:ComputerName | |
If (Test-Path "C:\Backups\$CompName") { | |
$Dest = "C:\Backups\$CompName" | |
} | |
cd $Dest | |
# Get all the files to compress | |
$fileList = Get-ChildItem -Path $Dest -Filter *.bak -Recurse | |
foreach ($file in $fileList) { | |
$zipFile = $file.DirectoryName + '\' + $file.Basename + '.zip' | |
if (-not (test-path($zipFile))) { | |
set-content $zipFile ("PK" + [char]5 +[char]6 + ("$([char]0)" * 18)) | |
(dir $zipFile).IsReadOnly = $false | |
} | |
$shellApplication = new-object -com shell.application | |
$zipPackage = $shellApplication.NameSpace($zipFile) | |
$zipPackage.CopyHere($file.FullName) | |
do | |
{ | |
Start-sleep -milliseconds 250 | |
} | |
while ($zipPackage.Items().count -eq 0) | |
# Remove-Item $file.Fullname | |
} | |
# Get all the files to upload | |
$fileList = Get-ChildItem -Path $Dest -Filter *.zip -Recurse | |
$maxSize = 0 | |
# Copy each file to bucket | |
foreach ($file in $fileList) { | |
$maxSize = ($maxSize, $file.Length | Measure -Max).Maximum | |
$localfile = $file.FullName | |
$filename = $file.Name | |
$key = $Prefix + '/' + $filename | |
$remoteObject = Get-S3Object -BucketName $Bucket -Key $key -Region us-west-2 | |
if ($remoteObject.Size -eq $null) { | |
Write-S3Object -File $localfile -BucketName $Bucket -Key $key -ServerSideEncryption AES256 | |
} | |
else { | |
write-host "$file exists" | |
} | |
Remove-Item $file.FullName | |
} | |
$backupDrive = $Dest.Substring(0,2) | |
$freeSpace = (Get-WmiObject Win32_LogicalDisk | ? { $_.DeviceId -like $Dest.Substring(0,2)}).FreeSpace | |
if ($freeSpace -lt 2*$maxSize) { | |
$message = "Free space less than 2* largest backup file on " + $env:ComputerName | |
$subject = "Backup drive space: " + $env:ComputerName | |
Publish-SNSMessage -TargetArn $ARN -Message $message -Subject $subject | |
} |
Author
rterbush
commented
Jan 7, 2016
InvalidOperationExceptio
+ FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.GetS3ObjectCmdlet
Write-S3Object : Access Denied
At C:\\windows\\temp\\tmphhfgwg.ps1:56 char:9
+ Write-S3Object -File $localfile -BucketName $Bucket -Key $key
-ServerSid ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Object], InvalidOperationException
- FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
Get-S3Object : Access Denied
At C:\windows\temp\tmphhfgwg.ps1:54 char:21 -
$remoteObject = Get-S3Object -BucketName $Bucket -Key $key -Region us-west-2
- FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...tS3ObjectCmdlet:GetS3ObjectCmdlet) [Get-S3Object], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.GetS3ObjectCmdlet
Write-S3Object : Access Denied
At C:\\windows\\temp\\tmphhfgwg.ps1:56 char:9
+ Write-S3Object -File $localfile -BucketName $Bucket -Key $key
-ServerSid ...\r\n+ ~
stderr:
Param : The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Administrator\appdata\local\temp\2\tmpbwosxv.ps1:3 char:1
+ Param(
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (Param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException�
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment