スナップショット(GCE)
事前準備
インスタンスを起動する
gcloud compute instances create gcp --preemptible --zone=us-west1-a --machine-type=e2-micro -q
スナップショットの取得
スナップショットを取得する
gcloud compute disks snapshot gcp --zone=us-west1-a --description "sample snapshot" --snapshot-names=sample-snapshot
Creating snapshot(s) sample-snapshot...done.
30秒ぐらい?でできた データほぼないとはいえかなり優秀なのではないか
GUIから見ても問題なくできているように見える
スナップショットの複製
スナップショット取るということは複製もやってみなければ
gcloud compute disks create "clone-instance" --size=10 --zone=asia-east1-a --source-snapshot=sample-snapshot
WARNING: You have selected a disk size of under [200GB]. This may result in poor I/O performance. For more information, see: https://developers.google.com/compute/docs/disks#performance.
Created [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/asia-east1-a/disks/clone-instance].
NAME: clone-instance
ZONE: asia-east1-a
SIZE_GB: 10
TYPE: pd-standard
STATUS: READY
gcloud compute instances create clone-gcp --zone=asia-east1-a --disk "name=clone-instance,device-name=sample-snapshot,mode=rw,boot=yes"
Created [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/asia-east1-a/instances/clone-gcp].
NAME: clone-gcp
ZONE: asia-east1-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE:
INTERNAL_IP: 10.140.0.2
EXTERNAL_IP: 34.80.202.218
STATUS: RUNNING
ここよくわからなかったので苦戦しましたが、
gcloud compute disks create "clone-instance" --size=10 --zone=asia-east1-a --source-snapshot=sample-snapshot
上記コマンドでclone-instanceというディスクを作成して、
gcloud compute instances create clone-gcp --zone=asia-east1-a --disk "name=clone-instance,device-name=sample-snapshot,mode=rw,boot=yes"
でclone-gcpというインスタンスをさっき作成したclone-instanceというディスクイメージから作成するよ
という意味だと理解しました。
GUIでインスタンスが複製されているか確認してみる
おお、いいですね
ゾーンまたいで簡単にインスタンスを複製できるのはクラウドの良さを感じますね
後片付け
#インスタンスの一覧を表示
gcloud compute instances list
NAME: gcp
ZONE: us-west1-a
MACHINE_TYPE: e2-micro
PREEMPTIBLE: true
INTERNAL_IP: 10.138.0.5
EXTERNAL_IP: 35.230.46.48
STATUS: RUNNING
NAME: clone-gcp
ZONE: asia-east1-a
MACHINE_TYPE: n1-standard-1
PREEMPTIBLE:
INTERNAL_IP: 10.140.0.2
EXTERNAL_IP: 34.80.202.218
STATUS: RUNNING
#インスタンス"gcp"を削除
gcloud compute instances delete gcp --zone=us-west1-a
The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and
specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost.
- [gcp] in [us-west1-a]
Do you want to continue (Y/n)? y
Deleted [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/us-west1-a/instances/gcp].
#インスタンス"clone-gcp"を削除
gcloud compute instances delete clone-gcp --zone=asia-east1-a
The following instances will be deleted. Any attached disks configured to be auto-deleted will be deleted unless they are attached to any other instances or the `--keep-disks` flag is given and
specifies them for keeping. Deleting a disk is irreversible and any data on the disk will be lost.
- [clone-gcp] in [asia-east1-a]
Do you want to continue (Y/n)? y
Deleted [https://www.googleapis.com/compute/v1/projects/<projectID>/zones/asia-east1-a/instances/clone-gcp].
# スナップショットの一覧を表示
gcloud compute snapshots list
NAME: sample-snapshot
DISK_SIZE_GB: 10
SRC_DISK: us-west1-a/disks/gcp
STATUS: READY
#スナップショット"sample-snapshot"を削除
gcloud compute snapshots delete sample-snapshot
The following snapshots will be deleted:
- [sample-snapshot]
Do you want to continue (Y/n)? y
Deleted [https://www.googleapis.com/compute/v1/projects/<projectID>/global/snapshots/sample-snapshot].
GUIからも確認
ディスク消してないか
# ディスクの一覧を表示
gcloud compute disks list
NAME: clone-instance
LOCATION: asia-east1-a
LOCATION_SCOPE: zone
SIZE_GB: 10
TYPE: pd-standard
STATUS: READY
# ディスク"clone-instance"を削除
gcloud compute disks delete clone-instance
Did you mean zone [asia-east1-a] for disk: [clone-instance] (Y/n)? y
The following disks will be deleted:
- [clone-instance] in [asia-east1-a]
Do you want to continue (Y/n)? y
Deleted [https://www.googleapis.com/compute/v1/projects/noble-feat-376216/zones/asia-east1-a/disks/clone-instance].
ヨシ!
今日はここまで、お疲れ様でした。