This page shows you how to copy, rename, and move objects. While some tools perform atomic object move operations, other tools simulate an object move operation by copying the object to a new specified location and then deleting the original object.
- For instructions on copying objects, see Copy objects .
- For instructions on moving or renaming objects by copying them, see Move or rename objects by copying .
- For instructions on renaming objects atomically, see Rename objects atomically .
We recommend using Storage Transfer Service to move more than 1 TB of data between buckets .
Before you begin
In order to copy, rename, or move objects, you must get the required IAM roles. The following sections describe IAM requirements for different use cases.
Copy objects (including moving or renaming by copying)
To get the permissions that you need to copy objects, ask your administrator to grant you the following IAM roles on the source bucket that contains the objects you want to move, or the destination bucket where you want to move the objects to:
- Storage Object Viewer (
roles/storage.objectViewer
) on the source bucket - Storage Object User (
roles/storage.objectUser
) on the destination bucket - To copy objects using the Google Cloud console:
Viewer basic role (
roles/viewer
) on both the source bucket and destination bucket, in addition toroles/storage.objectViewer
androles/storage.objectUser
These predefined roles contain the permissions required to copy objects. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to copy objects:
-
storage.objects.get
on the source bucket -
storage.objects.create
on the destination bucket -
storage.objects.delete
(required only if you're replacing or overwriting an object in the destination bucket as part of an object copy or move operation) on the destination bucket -
storage.objects.delete
(required only if you're moving an object using an underlying copy and delete operation) on the source bucket -
storage.folders.create
(required only if the object you're moving is located in a folder that you want to create in the destination bucket) on the destination bucket -
storage.objects.list
(required only if you're copying, moving, or renaming an object using the Google Cloud console) on the source and destination buckets -
storage.buckets.list
(required only if you're copying, moving, or renaming an object using the Google Cloud console) on the project that contains the source and destination buckets
You can also get these permissions with custom roles .
For information about granting roles on buckets, see Use IAM with buckets . For information about granting roles on projects, see Manage access to projects .
If the object you want to copy has certain features enabled, you might need
additional or alternative roles. For example, if the object you want to copy has
an object retention configuration you want to retain, you'll need a role on
the destination bucket that includes the storage.objects.setRetention
permission, such as the Storage Object Admin ( roles/storage.objectAdmin
) role.
For more information, see IAM permissions for Cloud Storage
.
Rename objects atomically
To get the permissions that
you need to rename objects atomically,
ask your administrator to grant you the Storage Object User
( roles/storage.objectUser
)
IAM role on the bucket that contains the object you want to rename.
This predefined role contains the permissions required to rename objects atomically. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to rename objects atomically:
-
storage.objects.move
-
storage.objects.create
-
storage.objects.delete
(required only if you're overwriting or replacing an object)
You can also get these permissions with custom roles .
For information about granting roles on buckets, see Use IAM with buckets .
Copy objects
This section describes how to copy objects. You can copy objects from one bucket to another.
Console
- In the Google Cloud console, go to the Cloud Storage Buckets
page.
-
In the list of buckets, click the name of the bucket that contains the object you want to copy.
The Bucket detailspage opens, with the Objectstab selected.
-
Navigate to the object, which may be located in a folder.
-
Click the Object overflowmenu ( more_vert ) associated with the object.
-
Click Copy.
The Copy objectpane appears.
-
In the Destinationfield, type the name of the destination bucket and the name for the copied object.
You can alternatively click Browseto select your destination, but browse options are limited to buckets in the current project.
-
Click Copy.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, see Troubleshooting .
Command line
Use the gcloud storage cp
command:
gcloud storage cp gs:// SOURCE_BUCKET_NAME / SOURCE_OBJECT_NAME gs:// DESTINATION_BUCKET_NAME / NAME_OF_COPY
Where:
-
SOURCE_BUCKET_NAME
is the name of the bucket containing the object you want to copy. For example,my-bucket
. -
SOURCE_OBJECT_NAME
is the name of the object you want to copy. For example,pets/dog.png
. -
DESTINATION_BUCKET_NAME
is the name of the bucket where you want to copy your object. For example,another-bucket
. -
NAME_OF_COPY
is the name you want to give the copy of your object. For example,shiba.png
.
If successful, the response is similar to the following example:
Copying gs://example-bucket/file.txt to gs://other-bucket/file-copy.txt Completed files 1/1 | 164.3kiB/164.3kiB
Client libraries
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
For more information, see the Cloud Storage Java API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Node.js
For more information, see the Cloud Storage Node.js API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Python
For more information, see the Cloud Storage Python API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .