Working with Snapshots on Google Compute Engine

Hands-On Lab

 

Photo of Matthew Ulasien

Matthew Ulasien

Team Lead Google Cloud in Content

Length

01:00:00

Difficulty

Beginner

This hands-on lab will help to provide experience working with snapshots on Compute Engine, both in the web console and command line format, which we will interact with via Cloud Shell.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Snapshots on Google Compute Engine

Introduction

This hands-on lab will help to provide experience working with snapshots on Compute Engine, both in the web console and command line format, which we will interact with via Cloud Shell.

Solution

Be sure to launch the lab in incognito mode (or your browser's 'private browsing' function) to avoid cached login issues. You will already have a GCE instance in your lab that we will use for the demonstration.

Create snapshot using web console

  1. Go to the top-left menu > Compute Engine > Snapshots
  2. Click Create snapshot
  3. Name snapshot "web-backup-v1"
  4. In Source Disk dropdown menu, select website
  5. Click Create

Make instance change - update website to VERSION 2

  1. Connect to the website instance using SSH from the Compute Engine web console

    • Navigate to Computer Engine in the menu on the top-left
    • Click SSH to the right of the VM Instance
  2. Enter the following command to replace index page with 'VERSION 2' instead of 'VERSION 1':

    sudo sed -i 's/VERSION 1/VERSION 2/' /var/www/html/index.html
  3. Exit SSH session

Create new snapshot from same instance using command line

  1. Open Cloud Shell and enter following command:

    gcloud compute disks snapshot website --snapshot-names web-backup-v2 --zone us-central1-a
  2. Verify snapshots using web console and Cloud Shell. Notice the size of the second snapshot compared to first:

    gcloud compute snapshots list
    gcloud compute snapshots describe web-backup-v2

Restore first snapshot using web console in new zone

  1. Go to top left menu > Compute Engine
  2. Click CREATE INSTANCE
  3. Name instance "website-restore-1"
  4. Choose a region/zone
  5. Change boot disk:
    • Select Snapshots
    • Select web-backup-v1
    • Click Select at the bottom
  6. Select box to allow HTTP traffic
  7. Click Create

Restore second snapshot using command line

  1. Navigate to Cloud Shell

  2. Create disk from snapshot:

    gcloud compute disks create website-restore-2 --source-snapshot web-backup-v2 --zone us-central1-a
  3. Create new instance from disk:

    gcloud compute instances create website-restore-2 --disk name=website-restore-2,boot=yes --zone us-central1-a --tags=http-server

Conclusion

Congratulations, you've completed this hands-on lab!