Created
March 15, 2025 15:57
-
-
Save kamarton/96f7889d0e8b0e88d2861e8fbbde22a6 to your computer and use it in GitHub Desktop.
Stop compute engine, detach disk, (delete snapshot id exists), create snapshot, delete disk (GCP, CLI, GCLOUD)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PROJECT=<project> | |
ZONE=<zone> | |
INSTANCE=<compute-engine-instance> | |
DISK=<disk-name> | |
SNAPSHOT=<snapshot-name> | |
REGION=<region> | |
echo stop vm - - - - - - - - - - - - - - - - - - - - - - | |
gcloud compute instances stop $INSTANCE \ | |
--project=$PROJECT | |
echo detach disk - - - - - - - - - - - - - - - - - - - - | |
gcloud compute instances detach-disk $INSTANCE \ | |
--disk $DISK \ | |
--project=$PROJECT \ | |
--zone $ZONE | |
echo delete snapshot - - - - - - - - - - - - - - - - - - | |
gcloud compute snapshots delete $SNAPSHOT \ | |
--project=$PROJECT \ | |
--zone $ZONE | |
echo create snapshot from disk - - - - - - - - - - - - - - - - | |
gcloud compute snapshots create $SNAPSHOT \ | |
--project=$PROJECT \ | |
--source-disk=$DISK \ | |
--source-disk-zone=$ZONE \ | |
--storage-location=$REGION | |
echo delete disk - - - - - - - - - - - - - - - - - - - - - - - - | |
gcloud compute disks delete $DISK \ | |
--zone $ZONE \ | |
--project=$PROJECT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment