https://cloud.google.com/compute/docs/disks/scheduled-snapshots?hl=ja
-- 1. 前作業
gcloud init
gcloud auth list
gcloud --version
gcloud projects create project01-9999999 \
--name="project01"
gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet
gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111
gcloud services enable compute.googleapis.com --project project01-9999999
-- 2. インスタンス作成
gcloud compute instances create vm01 \
--machine-type=e2-micro \
--image-project=centos-cloud \
--image=centos-7-v20221004 \
--network-interface=network-tier=STANDARD \
--labels key1=va1,key2=val2
gcloud compute instances list
gcloud compute disks list
gcloud compute snapshots list
-- 3. スナップショット スケジュールの作成
gcloud compute resource-policies create snapshot-schedule sche01 \
--description "sche01" \
--max-retention-days 1 \
--start-time 13:00 \
--hourly-schedule 1 \
--on-source-disk-delete apply-retention-policy
gcloud compute resource-policies list
gcloud compute resource-policies describe sche01
-- 4. スナップショット スケジュールをディスクに適用する
gcloud compute disks list
gcloud compute disks add-resource-policies vm01 \
--resource-policies sche01 \
--zone asia-northeast1-a
-- 5. スナップショット生成確認
gcloud compute snapshots list
gcloud compute snapshots describe vm01-asia-northeast1-a-11111111111111-11111111
-- 6. クリーンアップ
gcloud compute disks remove-resource-policies vm01 \
--resource-policies sche01 \
--zone asia-northeast1-a
gcloud compute resource-policies delete sche01 \
--region asia-northeast1
gcloud compute instances delete vm01 --quiet
gcloud projects list
gcloud projects delete project01-9999999 -q
gcloud beta billing projects unlink project01-9999999