Create and manage batch operation jobs
Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to create, view, list, cancel, and delete
storage batch operations jobs. It also describes how to use Cloud Audit Logs
with storage batch operations jobs.
Before you begin
To create and manage storage batch operations jobs, complete the steps in the following sections.
Configure Storage Intelligence
To create and manage storage batch operations jobs, configure
Storage Intelligence on the bucket where you want to run the job.
If you want to use a manifest for object selection, create a manifest file.
Using a manifest is one of the ways you can select objects to process in a
storage batch operations job.
Create a storage batch operations job
This section describes how to create a storage batch operations job.
To get the permissions that
you need to create a storage batch operations job,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
--clear-object-custom-contexts: Remove contexts with specific keys. You can also update specific contexts along with removing keys by using both the --clear-object-custom-contexts flag and one of the following flags:
--update-object-custom-contexts: Provide a map of key-value pairs.
The following example shows how to create a job to remove the context with key temp-id and update or insert context with key project-id and cost-center for all objects listed in manifest.csv:
use Google\Cloud\StorageBatchOperations\V1\Client\StorageBatchOperationsClient;use Google\Cloud\StorageBatchOperations\V1\CreateJobRequest;use Google\Cloud\StorageBatchOperations\V1\Job;use Google\Cloud\StorageBatchOperations\V1\BucketList;use Google\Cloud\StorageBatchOperations\V1\BucketList\Bucket;use Google\Cloud\StorageBatchOperations\V1\PrefixList;use Google\Cloud\StorageBatchOperations\V1\DeleteObject;/** * Create a new batch job. * * @param string $projectId Your Google Cloud project ID. * (e.g. 'my-project-id') * @param string $jobId A unique identifier for this job. * (e.g. '94d60cc1-2d95-41c5-b6e3-ff66cd3532d5') * @param string $bucketName The name of your Cloud Storage bucket to operate on. * (e.g. 'my-bucket') * @param string $objectPrefix The prefix of objects to include in the operation. * (e.g. 'prefix1') */function create_job(string $projectId, string $jobId, string $bucketName, string $objectPrefix): void{ // Create a client. $storageBatchOperationsClient = new StorageBatchOperationsClient(); $parent = $storageBatchOperationsClient->locationName($projectId, 'global'); $prefixListConfig = new PrefixList(['included_object_prefixes' => [$objectPrefix]]); $bucket = new Bucket(['bucket' => $bucketName, 'prefix_list' => $prefixListConfig]); $bucketList = new BucketList(['buckets' => [$bucket]]); $deleteObject = new DeleteObject(['permanent_object_deletion_enabled' => false]); $job = new Job(['bucket_list' => $bucketList, 'delete_object' => $deleteObject]); $request = new CreateJobRequest([ 'parent' => $parent, 'job_id' => $jobId, 'job' => $job, ]); $response = $storageBatchOperationsClient->createJob($request); printf('Created job: %s', $response->getName());}
JSON API
To define the list of objects for your batch operation job, you can choose one of the following source configurations:
Project as the source: Targets objects project-wide using a projectSource configuration. Instead of listing individual buckets or prefixes, you specify advanced filter parameters to query storage insights metadata dynamically. For more information, see the JSON API tab in Create a job using advanced filters.
Buckets as the source: Targets objects within specific buckets using a bucketList configuration. You must specify the target buckets and either a manifest CSV file (manifest_location) or object prefixes (include_object_prefixes).
Have gcloud CLI installed and initialized, which lets
you generate an access token for the Authorization header.
Create a JSON file that contains the settings for the storage batch operations job. The following are common settings to include:
Where STORAGE_CLASS_VALUE is the new storage class you want to transition the objects to. Supported storage classes include STANDARD, NEARLINE, COLDLINE, and ARCHIVE.
METADATA_KEY/VALUE is the
object's metadata key-value pair. You can specify
one or more pairs.
RETAIN_UNTIL_TIME is the date and time, in RFC 3339
format, until which the object is retained. For example,
2025-10-09T10:30:00Z. To set the retention configuration on an object, you'll
need to enable retention on the bucket which contains the object.
RETENTION_MODE is the retention mode, either Unlocked or
Locked.
When you send a request to update the RETENTION_MODE and RETAIN_UNTIL_TIME fields,
consider the following:
To update the object retention configuration, you must provide non-empty values for both
RETENTION_MODE and RETAIN_UNTIL_TIME fields; setting only one results in
an INVALID_ARGUMENT error.
You can extend the RETAIN_UNTIL_TIME value for objects in both Unlocked
or Locked modes.
The object retention must be in Unlocked mode if you want to do the
following:
Reduce the RETAIN_UNTIL_TIME value.
Remove the retention configuration. To remove the configuration, you'll need to
provide empty values for both RETENTION_MODE and RETAIN_UNTIL_TIME
fields.
If you omit both RETENTION_MODE and RETAIN_UNTIL_TIME fields, the
retention configuration remains unchanged.
PROJECT_ID is the ID or number of the project. For example, my-project.
JOB_NAME is the name of the storage batch operations job.
Get storage batch operations job details
This section describes how to get the storage batch operations job details.
To get the permissions that
you need to view a storage batch operations job,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
For jobs that include multiple buckets, you can view the progress and status of operations on individual buckets. To list the operations performed on buckets for a specific job, run the gcloud storage batch-operations bucket-operations list command:
gcloud storage batch-operations bucket-operations list --job=JOB_NAME
You can also filter the list to specific buckets using the --buckets flag:
gcloud storage batch-operations bucket-operations list --job=JOB_NAME --buckets=BUCKET_NAME_LIST
The following example shows how to list operations for bucket1 and bucket2 for the job my-job:
gcloud storage batch-operations bucket-operations list --job=my-job --buckets=bucket1,bucket2
Where:
JOB_NAME is the unique name of the storage batch operations job that you created. For example, my-job.
BUCKET_NAME_LIST is a comma-separated list of bucket names, without spaces between names. For example, bucket1,bucket2.
Describe a bucket operation
To view details for a specific bucket operation, you can use either of the following methods:
Use the gcloud storage batch-operations bucket-operations describe command with the operation resource name flag:
BUCKET_OPERATION_RESOURCE_NAME is the full resource path of the bucket operation. For example, projects/my-project/locations/global/jobs/my-job/bucketOperations/bo-1.
Use the gcloud storage batch-operations bucket-operations describe command with the operation bucket operation ID and job ID flags:
BUCKET_OPERATION_ID is the ID of the bucket operation.
JOB_NAME is the unique name of the storage batch operations job that you created. For example, my-job.
List storage batch operations jobs
This section describes how to list the storage batch operations jobs within a project.
To get the permissions that
you need to list storage batch operations jobs,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This section describes how to cancel a storage batch operations job within a project.
To get the permissions that
you need to cancel a storage batch operations job,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This section describes how to delete a storage batch operations job.
To get the permissions that
you need to delete a storage batch operations job,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
Create a storage batch operations job using Storage Insights datasets
To run a batch operations job on objects listed in a dataset, select one of the following options:
Use advanced filters: Filter objects dynamically at the project level directly in the Google Cloud CLI command.
Storage Insights datasets are created from periodic, point-in-time snapshots of your storage metadata. Each snapshot has a snapshot time that shows when the metadata was captured. When you run a batch job using advanced filters, this snapshot time determines which objects and versions are processed. By default, Storage batch operations automatically selects the latest snapshot time. To prevent operations on outdated data, job creation fails if the selected snapshot is more than two days old. For information about how to resolve this failure, see Troubleshooting Storage batch operations issues.
Use a manifest file: Generate a CSV manifest file by running a BigQuery query, and then provide it to the job.
The methods are described in the following sections.
Use advanced filters
Instead of creating a manifest file, you can use Common Expression Language (CEL) filters to select objects directly based on fields in your Storage Insights dataset. You can run jobs across multiple buckets in a project. When you use dataset filters for object selection, storage batch operations targets objects that are live and current as of the selected dataset snapshot. Consequently, the job only includes objects that have a NULL value for both softDeleteTime and timeDeleted at the time of the snapshot.
To get the permissions that
you need to create a storage batch operations job,
ask your administrator to grant you the
Storage Admin (roles/storage.admin) IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You can create the manifest for your storage batch operations job by
extracting data from BigQuery. To do so, you'll need to query the
linked dataset, export the resulting data as a CSV file, and save it to a
Cloud Storage bucket. The storage batch operations job can
then use this CSV file as its manifest.
Running the following SQL query in BigQuery on a Storage Insights
dataset view retrieves objects larger than 1 KiB that are named Temp_Training:
EXPORT DATA OPTIONS(
uri=`URI`,
format=`CSV`,
overwrite=OVERWRITE_VALUE,
field_delimiter=',') AS
SELECT bucket, name, generation
FROM DATASET_VIEW_NAME
WHERE bucket = BUCKET_NAME
AND name LIKE (`Temp_Training%`)
AND size > 1024 * 1024
AND snapshotTime = SNAPSHOT_TIME
Where:
URI is the URI to the bucket that contains the manifest. For example, gs://bucket_name/path_to_csv_file/*.csv. When you use the *.csv wildcard, BigQuery exports the result to multiple CSV files.
OVERWRITE_VALUE is a boolean value. If set to true, the export operation overwrites existing files at the specified location.
DATASET_VIEW_NAME is the fully qualified name of the Storage Insights dataset view in PROJECT_ID.DATASET_ID.VIEW_NAME format. To find the name of your dataset, view the linked dataset.
Where:
PROJECT_ID is the ID or number of the project. For example, my-project.
DATASET_ID is the name of the dataset. For example, objects-deletion-dataset.
VIEW_NAME is the name of the dataset view. For example, bucket_attributes_view.
BUCKET_NAME is the name of the bucket. For example, my-bucket.
SNAPSHOT_TIME is the snapshot time of the Storage Insights dataset view. For example, 2024-09-10T00:00:00Z.
Create a storage batch operations job using a manifest file
To create a storage batch operations job to process objects contained in the manifest, complete the following steps:
VPC Service Controls provides an additional layer of security for
storage batch operations resources. By placing projects within a service perimeter, you help protect
resources and services from requests that originate from outside the
perimeter. To learn more about VPC Service Controls service perimeter details for
storage batch operations, see
Supported products and limitations.
Use Cloud Audit Logs for storage batch operations jobs
Storage batch operations jobs record transformations on Cloud Storage objects in Cloud Audit Logs for Cloud Storage. Use Cloud Audit Logs with Cloud Storage to track these transformations. For details on how to enable audit logs, see Enabling audit logs. In the audit log entry, a callUserAgent metadata field with the value StorageBatchOperations indicates that the transformation was performed by storage batch operations.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-09-30 UTC."],[],[]]