lifecycle - Get or set lifecycle configuration for a bucket

Synopsis

gsutil lifecycle get gs://<bucket_name>
gsutil lifecycle set <config-json-file> gs://<bucket_name>...

Description

You can use the lifecycle command to get or set lifecycle management policies for a given bucket. This command is supported for buckets only, not objects. For more information, see Object Lifecycle Management.

The lifecycle command has two sub-commands:

Get

Gets the lifecycle management configuration for a given bucket. You can get the lifecycle management configuration for only one bucket at a time. To update the configuration, you can redirect the output of the get command into a file, edit the file, and then set it on the bucket using the set sub-command.

Set

Sets the lifecycle management configuration on one or more buckets. The config-json-file specified on the command line should be a path to a local file containing the lifecycle configuration JSON document.

Examples

The following lifecycle management configuration JSON document specifies that all objects in this bucket that are more than 365 days old are deleted automatically:

{
  "rule":
  [
    {
      "action": {"type": "Delete"},
      "condition": {"age": 365}
    }
  ]
}

The following empty lifecycle management configuration JSON document removes all lifecycle configuration for a bucket:

{}