Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Intelrunner/acf2e3f8355ac49245c0a92227a1c882 to your computer and use it in GitHub Desktop.
Save Intelrunner/acf2e3f8355ac49245c0a92227a1c882 to your computer and use it in GitHub Desktop.
Update all buckets in project to X soft_delete_duration (Google Cloud)
from google.cloud import storage
import os
def update_soft_delete():
"""Lists all buckets in a project."""
storage_client = storage.Client()
buckets = storage_client.list_buckets()
for bucket in buckets:
print ("****************")
print(f"OLD Soft delete duration of {bucket.name} is {bucket.soft_delete_policy.retention_duration_seconds}")
print("_____________")
bucket.soft_delete_policy.retention_duration_seconds = 604800
print(f"Soft delete duration of {bucket.name} is {bucket.soft_delete_policy.retention_duration_seconds}")
bucket.update()
print("****************")
update_soft_delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment