简体   繁体   English

如何使用PowerShell在本地备份S3 Bucket的内容

[英]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.

相关问题 如何使用Powershell访问Transfer Accelerated S3存储桶 - How to access Transfer Accelerated S3 bucket using Powershell 使用 PowerShell 脚本将 Amazon S3 存储桶内容复制到本地文件夹 - Copy Amazon S3 Bucket Contents to Local Folder using PowerShell Script 使用Powershell在Amazon s3存储桶中上传整个文件夹结构 - Upload whole folder structure in Amazon s3 bucket using powershell 使用PowerShell Core上传到Amazon S3存储桶 - Uploading to an Amazon S3 bucket with PowerShell Core 使用 powershell 在 s3 存储桶中创建一个新文件夹 - Create a new folder in s3 bucket with powershell 使用 Azure 管道将 RDS 数据库备份到 S3,错误 SQL Powershell 模块未安装在您的代理计算机上, - RDS Database backup to S3 using Azure Pipeline, Error SQL Powershell Module is not installed on your agent machine, 使用PowerShell将新文件从S3存储桶中新创建的文件夹复制到本地计算机 - Copying new files from newly created folders in my S3 bucket to my local machine using PowerShell 使用 PowerShell 递归删除 S3 存储桶下超过 30 天的文件而不删除文件夹 - Delete files older than 30 days under S3 bucket recursively without deleting folders using PowerShell 将IIS日志移至AWS S3存储桶的Powershell脚本 - Powershell script to move IIS logs to AWS S3 bucket Powershell脚本将文件传输到S3存储桶时出现问题 - Issue with a Powershell script transferring files to a S3 Bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM