gpt4 book ai didi

powershell - 我可以使用 powershell 在一个命令中复制 s3 中的 "folder"吗?

转载 作者:行者123 更新时间:2023-12-02 23:02:05 24 4
gpt4 key购买 nike

我有一个带有 stageproduction 前缀的 s3 存储桶。 QA 之后,我想将所有对象从阶段复制到生产中。我正在尝试了解如何使用一个命令执行此操作。

我的谷歌搜索仅显示以下内容,用于复制单个对象:

http://docs.aws.amazon.com/powershell/latest/reference/items/Copy-S3Object.html

我可以通过以下方式一次上传一个文件夹

Write-S3Object -BucketName $bucketName -Folder $myfolder -Keyprefix $Keyprefix

但是 Copy-S3Object 命令似乎不接受前缀和目标前缀,例如。

执行此操作的最佳方法是什么?

最佳答案

好的,看起来 AWS CLI 在很多情况下都是一个很好的解决方案,但实际上我在这里只能使用 Powershell。

这是我的解决方案:

$objects = Get-S3Object -BucketName $bucketName -KeyPrefix $stageKeyPrefix

foreach($object in $objects) {
$prodKey = $object.Key -replace $stageKeyPrefix, $prodKeyPrefix
Copy-S3Object -BucketName $bucket -Key $object.Key -DestinationKey $prodKey
}

关于powershell - 我可以使用 powershell 在一个命令中复制 s3 中的 "folder"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47832586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com