Summary
Add two Python scripts for auditing and restoring GCS bucket objects to a previous point-in-time using object versioning.
Scripts
gcs_version_audit.py (read-only)
- Lists all object versions in a GCS bucket
- Classifies each object: already correct, needs restore, or created after target date
- Reports total restore size and estimated Coldline retrieval cost
- Supports
--limit for testing, --show-all-versions for verbose output, and --prefix for scoping
gcs_restore.py (write, with safeguards)
- Restores all objects to their state at a given target datetime
- Dry-run by default — requires
--execute flag to make changes
- Even with
--execute, prompts for interactive yes confirmation
- Parallel execution with configurable worker count
- Optional
--delete-new flag to remove objects created after the target date
Use case
When a GCS bucket with object versioning enabled needs to be rolled back to a known-good state (e.g., after accidental bulk deletions or overwrites), these scripts provide a safe audit-then-restore workflow.
Requirements
google-cloud-storage Python package
- GCP credentials with read access (audit) or read+write access (restore)
- Object versioning must be enabled on the target bucket
Summary
Add two Python scripts for auditing and restoring GCS bucket objects to a previous point-in-time using object versioning.
Scripts
gcs_version_audit.py(read-only)--limitfor testing,--show-all-versionsfor verbose output, and--prefixfor scopinggcs_restore.py(write, with safeguards)--executeflag to make changes--execute, prompts for interactiveyesconfirmation--delete-newflag to remove objects created after the target dateUse case
When a GCS bucket with object versioning enabled needs to be rolled back to a known-good state (e.g., after accidental bulk deletions or overwrites), these scripts provide a safe audit-then-restore workflow.
Requirements
google-cloud-storagePython package