In this lab, you'll learn how to enable object versioning on Cloud Storage buckets and create lifecycle rules to automatically manage storage costs. Object versioning keeps previous versions of files when they're overwritten or deleted, which is critical for backup, compliance, and protecting against accidental data loss. Lifecycle rules automate storage management tasks like deleting old data, moving objects to cheaper storage classes, or cleaning up incomplete uploads.
Requirements to Pass This Lab
Create a bucket with name starting with lab-versioned-bucket-
Enable object versioning on the bucket
Upload at least one file to the bucket
Create at least one lifecycle rule
Before You Begin
Step 0: Authentication
How this works: You need a Google account that uses the same email address as your GCP Study Hub account. When you sign into that Google account, the system will be able to grant you temporary access to a GCP project when you start the lab.
Once your lab starts, use the "Open GCP Console" button from the lab portal to open the Google Cloud Console with your temporary lab project already selected.
Step 2: Navigate to Cloud Storage
In the left navigation menu, click on the hamburger menu (three horizontal lines)
Scroll down and find Cloud Storage
Click on Buckets
Alternatively, you can search for "Cloud Storage" in the search bar at the top.
Step 3: Create a Bucket with Versioning Enabled
Click the CREATE button at the top of the page
Name your bucket:
Start with lab-versioned-bucket-
Add a unique random suffix to make it your own. Examples: lab-versioned-bucket-xyz789, lab-versioned-bucket-abc456def, lab-versioned-bucket-q7w8e9
If you get "name already taken," add more unique characters
Choose where to store your data:
Select Region and choose us-central1
In the real world, you can choose any region, dual-region, or multi-region based on your users' locations and latency needs. For this lab, we're using us-central1 for cost control and security.
Choose a storage class: Select Standard. Standard class provides the best performance for frequently accessed data.
Choose how to control access: Select Uniform. Uniform access control applies permissions consistently across all objects in the bucket.
Enforce public access prevention:
Make sure "Enforce public access prevention on this bucket" is checked (should be checked by default)
This prevents any objects in the bucket from being publicly accessible on the internet, which is a security best practice. Even if someone accidentally makes an object public, this setting blocks it.
Advanced settings:
Continue until you get to the Data protection section
Find the checkbox for Object versioning
Check the box to enable object versioning
Leave the other versioning settings as defaults - you'll learn to manage version cleanup using lifecycle rules later in this lab.
Retention (For compliance): Leave this unchecked. Retention policies prevent deletion or modification of objects for a specified period of time, which is useful for regulatory compliance (like HIPAA or financial regulations). We're not using it in this lab because we need the ability to delete objects during cleanup.
Data encryption: Leave this as the default (Google-managed encryption key). This provides encryption at rest without you having to manage keys.
Click CREATE at the bottom
What just happened: You created a bucket with versioning enabled. When you upload a file with the same name multiple times, Cloud Storage will keep all versions instead of replacing the old one. Each version gets a unique generation number and timestamp.
Step 4: Download Sample File
Download this sample inventory file that you'll upload and modify to demonstrate versioning:
The file will be saved to your Downloads folder. You'll upload it, then edit it locally and upload it again to create new versions.
Step 5: Upload the Initial Version
Click on your bucket name to open it
Click the UPLOAD FILES button
Select inventory.txt from your Downloads folder
Wait for the upload to complete (should be instant for this small file)
You should see inventory.txt listed in your bucket
What you just did: You uploaded the first version of this file. Because versioning is enabled, this version will be preserved even when you upload newer versions with the same filename.
Step 6: Edit the File and Upload Version 2
Now you'll modify the file locally and upload it again with the same filename to create a new version.
On your computer, find inventory.txt in your Downloads folder
Open it in a text editor (Notepad on Windows, TextEdit on Mac, or any text editor)
Change some of the numbers. For example, change "Product A: 100 units" to "Product A: 85 units"
Change the date at the bottom to today's date
Save the file (keep the same filename: inventory.txt)
Back in the Cloud Storage console, click UPLOAD FILES again
Select inventory.txt from your Downloads folder
You'll see a dialog: "Resolve object conflict - inventory.txt already exists"
Select "Overwrite object" (this creates a new version instead of truly overwriting)
Click UPLOAD
What you just did: You uploaded a second version of the same filename. Without versioning, the old version would be permanently deleted. With versioning enabled, the old version is preserved as an archived (noncurrent) version.
View Your Versions
Click on inventory.txt in the bucket
Click the Version history tab at the top
You should see 2 versions listed:
The top one shows (Live object) - your most recent upload
The older version below it with a Restore button - your original upload
Each version shows details:
Generation: Unique timestamp-based ID (microseconds since Unix epoch)
MD5 hash: Cryptographic fingerprint of the file contents
CRC32C hash: Checksum for verifying data integrity
Storage class: Which tier the object is stored in (Standard, Nearline, Coldline, Archive). Notice that storage class is shown at the object level - you can set storage classes per individual object or even per version, not just at the bucket level. This allows you to move older versions to cheaper storage tiers while keeping current versions in Standard.
Size: File size in bytes
Notice that both versions exist and are consuming storage space
Step 7: Create Version 3
Create one more version to see how versions accumulate:
Edit inventory.txt again on your computer
Make different changes (update different product quantities, change the date)
Save the file
Upload inventory.txt to the bucket again (select "Overwrite object" when prompted)
Click on inventory.txt again to open the object details
Click the Version history tab at the top
You should now see 3 versions:
1 live version (most recent upload)
2 noncurrent versions (your previous edits)
What you have now: You have 3 versions of this file stored in Cloud Storage. This demonstrates how versions accumulate over time, which can add up to significant storage costs.
Step 8: Restore an Old Version
Now you'll restore version 2 (your first edit) to see how version recovery works in practice.
In the Version history tab, find your second-oldest version (your first edit, the middle one in the list)
Click the Restore button next to that version
Confirm the restore action
Look at the version history again. You should now see 4 versions:
Live object: The restored version (your first edit is back!)
3 noncurrent versions: Your original file, second edit, and third edit
Optional: Download the current file and open it to verify it contains your first edit's content
What just happened: Restoring didn't "undo" anything - it created a new version (version 4) that's a copy of version 2's content. The version you restored from still exists as a noncurrent version. This means you can restore as many times as you want without losing any history.
Real-World Restore Scenarios
When you'd use restore in production:
Accidental deletion: Someone deletes a critical file - restore the most recent version
Bad deployment: A new application config file breaks production - restore yesterday's working version
Data corruption: A file gets corrupted - restore from a known-good version
Rollback: A website update has bugs - restore the previous version of HTML/CSS/JS files
Compliance/audit: Legal team needs to see what a document looked like 6 months ago - restore that specific version
Important: Restore creates a new "live" version. The file you're restoring from remains unchanged in the version history. This is different from some systems where "undo" actually removes history.
Real World vs Lab Environment
In this lab:
You're creating versions manually by uploading files
You can see the versions immediately in the console
Files are tiny (a few KB), so storage costs are negligible
In production (with versioning enabled):
Versions are created automatically whenever files are overwritten or deleted
A database backup script might create daily versions of a 100GB database
User photo uploads might create versions when users re-upload profile pictures
Build systems might overwrite artifact files with each new build
Each version consumes storage space and increases your monthly bill
Step 9: Create a Lifecycle Rule to Delete Old Versions
Lifecycle rules automate cleanup by deleting or archiving old versions after a specified time period. You'll create a rule that deletes noncurrent versions after 7 days.
Go back to the bucket list (click Buckets in the left menu)
Find your bucket (lab-versioned-bucket-...) and click on it to open it
Click Lifecycle near the center of the screen
You'll see some default lifecycle rules that were automatically created when you enabled versioning (like "Delete object 1+ days since becoming noncurrent"). Delete all existing rules by clicking the trash icon next to each one.
Now click ADD A RULE to create your own custom rule
Select object action:
Check the box for Delete object
This action will permanently remove old versions to save storage costs
Click CONTINUE
Select object conditions:
Find the Days since noncurrent option
Check this box
Enter 7 in the text field
This means "delete versions that have been noncurrent (archived) for 7 or more days"
Click CONTINUE
Review the rule summary and click CREATE
What you just configured: Your bucket will now automatically delete old versions after they've been noncurrent for 7 days. The live (current) version is never affected by this rule.
How Lifecycle Rules Work in Production
In this lab:
You created a rule with a 7-day retention period
The rule is configured but won't execute during this 30-minute lab
You won't see automatic deletion happen
In production (what happens after this lab):
Google Cloud evaluates lifecycle rules about once per day
The system scans objects in buckets with lifecycle rules
For each object, it checks if the conditions match (in this case: noncurrent for 7+ days)
If conditions match, the specified action is executed (delete the old version)
This happens automatically without any manual intervention
Example timeline in production:
Day 0 (Monday): You upload report_v1.pdf
Day 1 (Tuesday): You upload report_v2.pdf. Version 1 becomes noncurrent. Lifecycle system notes: "Delete in 7 days"
Day 2-7: Version 1 sits as noncurrent, still stored, still billed
Day 8 (Tuesday 2:00 AM): Lifecycle batch runs. Finds version 1 (noncurrent for 7 days). Deletes version 1
Day 8 (9:00 AM): You check the bucket. Only version 2 exists. Storage reduced, costs lowered
Important: Deleted versions cannot be recovered. Once the lifecycle rule deletes a version, it's gone forever. Choose your retention period carefully based on your backup and compliance needs.
Step 10: Review Common Lifecycle Patterns
While you created a simple delete rule, lifecycle management supports many strategies. Here are patterns used in production:
Pattern 1: Version Cleanup (what you just created)
Action: Delete
Condition: Noncurrent time greater than 7-30 days
Use case: Keep recent versions for rollback, delete old ones to save costs
Example: Database backups, application config files, user document uploads
Pattern 2: Archive Old Data
Action: Set storage class to Nearline or Coldline
Condition: Age greater than 90 days
Use case: Logs, backups you rarely access but need to keep
This will open in a new tab. Follow the instructions there to validate your work and get your completion token.
Submit Your Completion Token
After validating your lab, you'll receive a token. Paste it below and click "Validate Token" to mark this lesson complete.
Note: The "Mark Lesson Complete" button will not do anything if you are not in an actual lesson - but congratulations, you successfully completed the lab!
Key Takeaways
What you configured in this lab:
Object versioning to preserve previous versions of files
Lifecycle rule to automatically delete old versions after 7 days
Uploaded multiple versions of the same file to demonstrate versioning
How this works in production:
Applications automatically create versions when overwriting files
Lifecycle rules run daily to enforce retention policies
Automatic cleanup reduces storage costs without manual intervention
Balances data protection (keep recent versions) with cost optimization (delete old versions)
When to use versioning with lifecycle management:
Application backups (keep last 30 days, delete older)
User file uploads (protect against accidental deletion)
Database exports (daily snapshots with retention policy)
Log files (keep recent for debugging, archive or delete old)
Compliance requirements (retain for specific period, then auto-delete)
When NOT to use versioning:
Static website files (rarely change, version history not needed)
Public datasets (final data, won't be overwritten)
Already archived data (final state, no future updates)
Cost-sensitive projects with very limited budgets (versioning increases storage)