Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a folder in GCS using gsutil

I can't rename an existing folder in GCS. How do I do this?

As per the documentation, this should be:

gsutil mv gs://my_bucket/olddir gs://my_bucket/newdir

However, what happens is that olddir is placed under newdir, i.e the directory structure is like this (after the call to gsutil mv):

my_bucket
    newdir
        olddir

instead of (what I would expect)

my_bucket
    newdir

I've tried all four combinations of putting trailing slashes or not, but none of them worked.

like image 505
knub Avatar asked Aug 20 '18 09:08

knub


2 Answers

This is a confirmed bug in GCS, see https://issuetracker.google.com/issues/112817360

It actually only happens, when the directory name of newdir is a substring of olddir. So the gsutil call from the question actually works, but the following one would not:

gsutil mv gs://my-organization-empty-bucket/dir_old gs://my-organization-empty-bucket/dir
like image 162
knub Avatar answered Sep 19 '22 07:09

knub


I reproduced your case by having a bucket with a folder named olddir of which I want to move the content to newdir folder.

the following command:

 gsutils mv gs://<bucketname>/olddir gs://<bucketname>/newdir

moved the whole content of folder to the newly created newdir folder.

Olddir and newdir folders were then at the same level, in the bucket root. after that I just had to remove the folder called olddir.

Objects in a bucket cannot be renamed.

The gsutil mv command does not remove the previous folder object like the mv comand would do in Unix CLI.

I guess that if you have tried moving folders several times by using "/" characters placed differently, the structure and hierarchy of the folders will have changed after issuing the initial command.

Please try again from the beginning.

Bear in mind that once you have a subfolder inside a folder, objects will have to be moved one by one using the full path.

like image 24
Tzigan Avatar answered Sep 21 '22 07:09

Tzigan