About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

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: