英文:
Move files within same GCP storage bucket and keep version history
问题
如何将同一存储桶中的文件移动到不同文件夹,同时保留它们的版本历史记录?我找不到gsutil mv/cp
的相关选项。
英文:
How do you move files within the same storage bucket to different folders while keeping their version history? I couldn't find any related option for gsutil mv/cp
.
答案1
得分: 4
使用gsutil mv
移动对象(例如,使用gsutil mv
)是通过复制然后删除来完成的,因此移动的对象实际上是一个新对象。无法将旧对象的版本历史重新关联到新对象上。
gsutil cp
支持复制非当前版本 的文件,由于移动只是复制后跟随删除,您可以首先使用元数据保留选项进行复制,然后再删除。
gsutil cp -A gs://bucket-name/oldDir/file gs://bucket-name/newDir/file
gsutil rm gs://bucket-name/oldDir/file
英文:
Moving objects (e.g., using gsutil mv
) is accomplished using a copy followed by a delete, so the moved object is really a new object. There's no way to re-associate the version history of the old object to the new object.
gsutil cp
supports copying noncurrent versions of files and since a move is just a copy followed by a delete, you could first copy with the metadata preservation option and then delete.
gsutil cp -A gs://bucket-name/oldDir/file gs://bucket-name/newDir/file
gsutil rm gs://bucket-name/oldDir/file
答案2
得分: 0
使用 gsutil mv
命令将允许您对每个对象执行从源到目标的复制,然后删除源。
另外,正如 @John Henley 在评论中提到的,以及根据文档所述。
请注意,尽管 Cloud Storage 中的某些工具使对象的移动或重命名操作看起来像是唯一的操作,但它们始终是原始对象的复制操作,然后是删除操作,因为对象是不可变的。
英文:
Answering as a Community Wiki, so that it may help others too.
Using gsutil mv
command will allow you to perform a copy from source to destination followed by removing the source for each object.
Also as @John Henley stated in the comment and as per the Documentation.
>Note that while some tools in Cloud Storage make an object move or rename appear to be a unique operation, they are always a copy operation followed by a delete operation of the original object, because objects are immutable.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论