About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

Manipulate Versions of Cloud Storage Data


  1. Create a standard regional bucket with your closest region with a globally unique name.
gsutil mb -l (YOUR_REGION) gs://(BUCKET_NAME)
  1. Enable versioning for the bucket.
gsutil versioning set on gs://(BUCKET_NAME)
  1. In your Cloud Shell session, create a text file called ‘file.txt’. In the file, add the text ‘version 1’, then save the changes.
vim file.txt
Hit 'I' to Insert, type 'version 1', ESC key, :wq
  1. Copy ‘file.txt’ to your bucket.
gsutil cp file.txt gs://(BUCKET_NAME)
  1. Edit the ‘file.txt’ in Cloud Shell to say ‘version 2’ instead of ‘version 1’, then save the change.
vim file.txt
Hit 'I' to Insert, type 'version 2' in place of 'version 1', ESC key, :wq
  1. Copy ‘file.txt’ to your bucket again.
gsutil cp file.txt gs://(BUCKET_NAME)
  1. Edit the ‘file.txt’ in Cloud Shell to say ‘version 3’ instead of ‘version 2’, then save the change.
vim file.txt
Hit 'I' to Insert, type 'version 3' in place of 'version 2', ESC key, :wq
  1. Copy ‘file.txt’ to your bucket one more time.
gsutil cp file.txt gs://(BUCKET_NAME)
  1. Delete ‘file.txt’ from Cloud Shell.
rm file.txt
  1. List the contents of your bucket.
gsutil ls gs://(BUCKET_NAME)
  1. List the contents of your bucket again, but show all versions of your document.
gsutil ls -a gs://(BUCKET_NAME)
  1. Copy ‘file.txt’ from your bucket to Cloud Shell without specifying a generation number. View the contents of the file, what text do you have in the ‘version [X]’ line?
gsutil cp gs://(BUCKET_NAME)/file.txt .
  1. Delete ‘file.txt’ from Cloud Shell.
rm file.txt
  1. Copy ‘file.txt’ from your bucket to Cloud Shell, this time specifying the highest generation number. View the contents of the file, what text do you have in the ‘version [X]’ line?
gsutil cp gs://(BUCKET_NAME)/file.txt#(HIGHEST_GENERATION) .
  1. Delete ‘file.txt’ from Cloud Shell.
rm file.txt
  1. Copy ‘file.txt’ from your bucket to Cloud Shell specifying the lowest generation number. View the contents of the file, what text do you have in the ‘version [X]’ line?
gsutil cp gs://(BUCKET_NAME)/file.txt#(LOWEST_GENERATION) .
  1. Delete ‘file.txt’ from Cloud Shell.
rm file.txt
  1. Delete ‘file.txt’ from your bucket.
gsutil rm gs://(BUCKET_NAME)/file.txt
  1. From your web console, view the contents of your bucket. Is there anything there?
View Cloud Storage Browser in the web console.
  1. From Cloud Shell list contents of your bucket. Is there anything there?
gsutil ls gs://(BUCKET_NAME)
  1. From Cloud Shell list contents of your bucket again, but use the option to view details/versions. Is there anything there now?
gsutil ls -a gs://(BUCKET_NAME)
  1. Restore the oldest version of your ‘file.txt’ file in the bucket as the live version. It will be the one with the lowest generation number.
gsutil cp gs://(BUCKET_NAME)/file.txt#(LOWEST_GENERATION_NUMBER) gs://(BUCKET_NAME)/file.txt
  1. From your web console, view the contents of your bucket. Click the ‘file.txt’ file to open it and observe which version text is in the document.
  1.  Delete ‘file.txt’ from Cloud Shell and delete ALL versions of ‘file.txt’ from your bucket.
gsutil rm -r gs://(BUCKET_NAME)/file.txt
  1. From Cloud Shell list contents of your bucket one last time and use the option to view details/versions. Is there anything there now? There should not be as we recursively deleted all versions.
gsutil ls -a gs://(BUCKET_NAME)

No comments: