This page describes how to enable, disable, and check the status of Object Versioning on a bucket. See Using versioned objects to learn how to list, restore, and delete the objects that are retained by Object Versioning.
Required roles
To get the permissions that you need to set and manage Object Versioning
on a bucket, ask your administrator to grant you the Storage Admin
( roles/storage.admin
) IAM role on the bucket or the project
that contains the bucket. This predefined role
contains the permissions
required to set and manage Object Versioning for a bucket. To see the exact
permissions that are required, expand the Required permissionssection:
Required permissions
-
storage.buckets.get
-
storage.buckets.update
-
storage.buckets.list
- This permission is only required if you plan on using the Google Cloud console to perform the instructions on this page.
You might also be able to 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 .
Set Object Versioning on a bucket
Console
- In the Google Cloud console, go to the Cloud Storage Buckets
page.
-
In the list of buckets, click the name of the bucket for which you want to enable or disable Object Versioning.
-
Select the Protectiontab near the top of the page.
The current status of Object versioning is found in the Object versioningsection.
-
In the Object versioningsection, click the current status to make changes to it.
The Object versioningdialog appears.
- If you're enabling Object Versioning and you want to minimize storage costs, select the Add recommended lifecycle rules to manage version costscheckbox.
-
Click Confirm.
Command line
Use the gcloud storage buckets update
command with the
appropriate flag:
gcloud storage buckets update gs:// BUCKET_NAME
FLAG
Where:
-
BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
. -
FLAG
is either--versioning
to enable Object Versioning or--no-versioning
to disable it.
If successful, the response looks similar to the following example:
Updating gs://my-bucket/... Completed 1
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket:
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 .
The following sample enables Object Versioning on a bucket:
The following sample disables Object Versioning on a bucket: