Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kirilkirkov/b959d8c5bd6acd283f9971afa1d28297 to your computer and use it in GitHub Desktop.
Save kirilkirkov/b959d8c5bd6acd283f9971afa1d28297 to your computer and use it in GitHub Desktop.
Restore soft-deleted google cloud bucket storage objects with versioning with gcloud (CLI)

Get the list of soft-deleted objects in a bucket

gcloud storage ls gs://blog --soft-deleted --recursive

Restore a specific soft-deleted object

gcloud storage restore gs://BUCKET_NAME/OBJECT_NAME#GENERATION_NUMBER

Restore all soft-deleted objects in a bucket

gcloud storage ls gs://blog --soft-deleted --recursive | while read -r object; do echo "Restoring of object: $object" gcloud storage restore "$object" done

Restore all soft-deleted objects in a bucket asynchronously

gcloud storage restore gs://blog/** --async gcloud storage operations describe projects/_/buckets..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment