AWS CLI用于复制S3上较旧版本的文件。

huangapple go评论60阅读模式
英文:

AWS CLI for copying an older version of a file on s3

问题

你可以使用AWS命令行界面(awscli)将版本化的存储桶中的内容复制到S3本身。通常情况下,可以使用以下命令:

aws s3 cp from-loc to-loc

英文:

I have a versioned bucket. I know that I can download older versions, but can I also copy with the aws command line interface (awscli) to s3 itself? Normally this would be something

aws s3 cp from-loc to-loc

答案1

得分: 2

copy-object — AWS CLI命令参考 中,您可以使用以下命令:

aws s3api copy-object --bucket DESTINATION_BUCKET --key DESTINATION_FILENAME --copy-source 'SOURCE_BUCKET/SOURCE_FILENAME?versionId=VERSION_ID'

请注意,versionId--copy-source 的末尾指定为:?versionId=...

我尝试过它,它正常工作:

$ aws s3api copy-object --bucket my_bucket --key version-output --copy-source 'my_bucket/IMG.jpg?versionId=OXxABkv6CbZ1TFY_oupeHRweEdBJa7_K'
{
    "CopySourceVersionId": "OXxABkv6CbZ1TFY_oupeHRweEdBJa7_K",
    "VersionId": "DJOCWGV79gq01WGVv4BIPIpfBDAPtYLI",
    "ServerSideEncryption": "AES256",
    "CopyObjectResult": {
        "ETag": "\"cf0accb1b590bc16f3806b270a03132d\"",
        "LastModified": "2023-06-06T08:13:50+00:00"
    }
}
英文:

From copy-object — AWS CLI Command Reference you can use:

aws s3api copy-object --bucket DESTINATION_BUCKET --key DESTINATION_FILENAME --copy-source 'SOURCE_BUCKET/SOURCE_FILENAME?versionId=VERSION_ID'

Note that the versionId is specified at the end of the --copy-source with: ?versionId=...

I tried it and it worked correctly:

$ aws s3api copy-object --bucket my_bucket --key version-output --copy-source 'my_bucket/IMG.jpg?versionId=OXxABkv6CbZ1TFY_oupeHRweEdBJa7_K'
{
    "CopySourceVersionId": "OXxABkv6CbZ1TFY_oupeHRweEdBJa7_K",
    "VersionId": "DJOCWGV79gq01WGVv4BIPIpfBDAPtYLI",
    "ServerSideEncryption": "AES256",
    "CopyObjectResult": {
        "ETag": "\"cf0accb1b590bc16f3806b270a03132d\"",
        "LastModified": "2023-06-06T08:13:50+00:00"
    }
}

huangapple
  • 本文由 发表于 2023年6月6日 15:27:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定