Fix GCP Cloud Storage Bucket Version Errors
When working with GCP Cloud Storage, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with bucket version and shows the exact fix.
A Common Mistake
Enabling object versioning without a lifecycle rule to manage old versions, leading to unlimited storage costs from accumulated object versions.
The incorrect command:
gsutil versioning set on gs://my-bucket
Error output:
Enabling versioning for gs://my-bucket...
Versioning is enabled. Every object update creates a new version and the old version is retained indefinitely. After 6 months, the bucket contains 500,000 object versions costing $200/month in storage fees. Live objects are only 10 GB but archived versions are 500 GB.
The Correct Approach
The right way to configure bucket version in GCP Cloud Storage:
gsutil versioning set on gs://my-bucket && gsutil lifecycle set lifecycle.json gs://my-bucket
# lifecycle.json:
# {"rule": [{"action": {"type": "Delete"}, "condition": {"numNewerVersions": 3}}]}
Successful result:
Enabling versioning for gs://my-bucket...
Setting lifecycle configuration...
Versioning is on and old versions are automatically deleted when there are more than 3 newer versions of the same object. This limits storage cost growth.
How to Prevent This
Always pair versioning with lifecycle rules for cost control. Use numNewerVersions to keep only recent versions. Monitor version storage with gsutil du -s gs://bucket (lists live + archived). Versioning protects against accidental deletion but also costs. Test with 30-day lifecycle evaluation before enabling in production.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro