Here’s an example of how to restore all the disks of a GCP VM from snapshots.

<pre lang="bash">

# Set variables

# Get list of disks attached to the instance
DISKS=$(gcloud compute instances describe ${INSTANCE_NAME} \
--project ${PROJECT_ID} \

# Loop through each disk and restore from most recent snapshot
for DISK in $DISKS
  # Get most recent snapshot for the disk
  SNAPSHOT=$(gcloud compute snapshots list \
  --project ${PROJECT_ID} \
  --filter="sourceDisk=${INSTANCE_NAME}/${DISK} AND status=READY" \
  --sort-by="~creationTimestamp" \
  --format="value(name)" | head -n 1)

  # Restore the disk from the snapshot
  gcloud compute disks create ${DISK} \
  --project ${PROJECT_ID} \
  --source-snapshot ${SNAPSHOT} \
  --zone=us-central1-a \
  --labels restored-from=${SNAPSHOT}

  # Attach the disk to the instance
  gcloud compute instances attach-disk ${INSTANCE_NAME} \
  --disk=${DISK} \
  --project ${PROJECT_ID} \