Moving and renaming buckets

When you create a bucket, you permanently define its name, its geographic location, and the project it is part of. However, you can effectively move or rename your bucket:

  • If there is no data in your old bucket, delete the bucket and create another bucket with a new name, in a new location, or in a new project.

  • If you have data in your old bucket, create a new bucket with the desired name, location, and/or project, copy data from the old bucket to the new bucket, and delete the old bucket and its contents. The steps below describe this process.

    Note that if you want your new bucket to have the same name as your old bucket, you must move your data twice: an intermediary bucket temporarily holds your data so that you can delete the original bucket and free up the bucket name for the final bucket.

To move your data from one bucket to another:

Console

Use the Cloud Storage Transfer Service from within Google Cloud Console to copy data from one Cloud Storage bucket to another:

  1. If you don't have a destination bucket yet, make sure you create a bucket.
  2. Open the Transfer page in the Google Cloud Console.

    Open the Transfer page

  3. Click Create transfer job.
  4. Follow the step-by-step walkthrough, clicking Continue as you complete each step:

    • Select Source: Use Google Cloud Storage Bucket as your selected source, and click Browse to find and select the bucket you want to move your objects out of.

    • Select Destination: Click Browse to find and select the bucket you want to move your objects into.

      Additionally, select the checkbox Delete source objects after the transfer completes.

    • Configure Transfer: You can ignore this section.

  5. After you complete the step-by-step walkthrough, click Create.

    This begins the process of copying objects from your old bucket into your new one. This process may take some time; however, after you click Create, you can navigate away from the Google Cloud Console.

    To view the transfer's progress: Open the Transfer page in the Google Cloud Console.

    Open the Transfer page

    See Troubleshooting for how to get detailed error information about failed operations in the Cloud Storage browser.

  6. Once the transfer completes, you don't need to do anything to delete the objects from your old bucket if you selected the Delete source objects after the transfer completes checkbox during setup. You may, however, want to also delete your old bucket, which you must do separately.

gsutil

  1. Make sure you have at least gsutil 4.12 installed.
  2. If you don't have a destination bucket yet, make sure you create a bucket.
  3. Use the gsutil cp command, with the -r option, to recursively copy all your objects from the source bucket to the destination bucket:

    gsutil cp -r gs://SOURCE_BUCKET/* gs://DESTINATION_BUCKET

    Where:

    • SOURCE_BUCKET is the name of your original bucket. For example, old-bucket.
    • DESTINATION_BUCKET is the name of the bucket you are moving your data to. For example, my-bucket.
  4. Use the gsutil rm command, with the -r option, to recursively delete all your objects from the source bucket, as well as the source bucket itself:

    gsutil rm -r gs://SOURCE_BUCKET

    Where SOURCE_BUCKET is the name of your original bucket. For example, old-bucket.

    Or, to delete the objects but keep the source bucket:

    gsutil rm -a gs://SOURCE_BUCKET/**

REST APIs

JSON API

Use the JSON API's rewrite method to copy data in limited-sized chunks over multiple requests. When doing so, you must loop and call the rewrite method until all the data are moved:

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. If you don't have a destination bucket yet, make sure you create a bucket.

  3. Use cURL and the JSON API rewrite method to copy data from a source bucket to a destination bucket:

    curl -X POST \
     -H "Authorization: Bearer OAUTH2_TOKEN" \
     -H "Content-Length: 0" \
     "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET/o/OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET/o/OBJECT_NAME"

    Where:

    • OAUTH2_TOKEN is the access token you generated in Step 1.
    • SOURCE_BUCKET is the name of your original bucket. For example, old-bucket.
    • OBJECT_NAME is the name of the object you want to copy. For example, pets/dog.png.
    • DESTINATION_BUCKET is the name of the bucket you are moving your data to. For example, my-bucket.

    If the object is, for example, 10 GB in size, the response to this request looks like the following example:

    {
     "kind": "storage#rewriteResponse",
     "totalBytesRewritten": 1048576,
     "objectSize": 10000000000,
     "done": false,
     "rewriteToken": TOKEN_VALUE
    }
  4. Use the rewriteToken in a subsequent request to continue copying data:

    curl -X POST \
     -H "Authorization: Bearer OAUTH2_TOKEN" \
     -H "Content-Length: 0" \
     -d '{"rewriteToken": "TOKEN_VALUE"}' \
     "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET/o/OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET/o/OBJECT_NAME"

    Where:

    • OAUTH2_TOKEN is the access token you generated in Step 1.
    • TOKEN_VALUE is the rewriteToken value returned in the previous step.
    • SOURCE_BUCKET is the name of your original bucket. For example, old-bucket.
    • OBJECT_NAME is the name of the object you want to copy. For example, pets/bunny.png.
    • DESTINATION_BUCKET is the name of the bucket you are moving your data to. For example, my-bucket.

    When all of the data is copied, the last response has a done property equal to true, there is no rewriteToken property, and the metadata of the copied-to object is included in the resource property.

    {
      "kind": "storage#rewriteResponse",
      "totalBytesRewritten": 10000000000,
      "objectSize": 10000000000,
      "done": true,
      "resource": objects Resource
    }
  5. Use cURL and the and the JSON API delete method to remove the original version of your data with the following command:

    curl -X DELETE \
    -H "Authorization: Bearer OAUTH2_TOKEN" \
    "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET/o/OBJECT_NAME"

    Where:

    • OAUTH2_TOKEN is the access token you generated in Step 1.
    • SOURCE_BUCKET is the name of your original bucket. For example, old-bucket.
    • OBJECT_NAME is the name of the object you want to delete. For example, pets/dog.png.

What's next