[英]How to backup the contents of an S3 Bucket locally using PowerShell
I have created this function to pull objects from my S3 Bucket. 我创建了这个函数来从S3 Bucket中提取对象。 It works but because of the -Key parameter I can only do one file at a time. 它有效,但由于-Key参数,我一次只能做一个文件。
Is there anyway to back up the entire contents of the bucket without writing multiple Copy-S3Object cmdlets? 无论如何备份存储桶的全部内容而不编写多个Copy-S3Object cmdlet?
function CopyFromS3ToFolder($S3_Bucket, $S3_Folder_Destination, $S3_Key, $S3_SecretKey, $S3_AccessKey, $S3_Region)
{
#http://docs.aws.amazon.com/powershell/latest/reference/Index.html (Amazon Simple Storage Service)
#version AWSToolsAndSDKForNet_sdk-2.0.11.0-ps-2.0.11.0-tk-1.6.5.2
Write-Host "Copying from S3 to Local Directory"
Write-Host "Folder Name :$S3_Folder_Destination"
Copy-S3Object -BucketName $S3_Bucket -LocalFile $S3_Folder_Destination -SecretKey $S3_SecretKey -AccessKey $S3_AccessKey -Region $S3_Region -Key $S3_Key
}
您可以使用Get-S3Object
获取所需的键,然后将其传递给Copy-S3Object
,如下所示:
Get-S3Object -bucketname "Bucket1" | %{ Copy-S3Object -Key $_.key -LocalFile "path" }
$objects = Get-S3Object -bucketname $S3_Bucket -SecretKey $S3_SecretKey -AccessKey $S3_AccessKey -Region $S3_Region -KeyPrefix 8.9.2014
foreach($key in $objects.key)
{
$filename = $key -replace "8.9.2014/"
Copy-S3Object -Bucket $S3_Bucket -Key $key "$S3_Folder_Destination\$filename" -SecretKey $S3_SecretKey -AccessKey $S3_AccessKey -Region $S3_Region
}
see: https://forums.aws.amazon.com/thread.jspa?messageID=441291 请参阅: https : //forums.aws.amazon.com/thread.jspa?messageID = 441291
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.