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
.
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