Google-Cloud-Platform

Google Cloud Compute Engine 永久性磁碟快 照計劃不起作用

  • November 23, 2020

我在 GCP 上創建了一個帶有 terraform 的 VM,並且還分別使用 google_compute_disk、google_compute_resource_policy、google_compute_disk_resource_policy_attachment 資源創建了一個永久磁碟,以便還將快照計劃附加到磁碟

這是兩天前的事,還沒有創建快照。

有沒有人遇到過類似的問題?

計劃設置為每天。

這是我使用的 terraform 配置


resource "google_compute_disk" "fast_storage" {
 name = "${var.env}-fast-disk"
 type = "pd-ssd"
 size = 50 #GiB
 zone = var.zone
 labels = {
   environment = var.env
   type        = "ssd"

 }
 physical_block_size_bytes = 4096
}


resource "google_compute_resource_policy" "backup_policy" {
 name   = "${var.env}-backup-policy"
 region = var.region
 snapshot_schedule_policy {
   schedule {
     daily_schedule {
       days_in_cycle = 1
       start_time    = "04:00"
     }
   }
   retention_policy {
     max_retention_days    = 5
     on_source_disk_delete = "KEEP_AUTO_SNAPSHOTS"
   }
   snapshot_properties {
     labels = {
       environment = var.env
       type        = "ssd"
     }
     storage_locations = ["eu"]
     guest_flush       = true
   }
 }

}


resource "google_compute_disk_resource_policy_attachment" "backup_policy_attachment" {
 name = google_compute_resource_policy.backup_policy.name
 disk = google_compute_disk.fast_storage.name
 zone = var.zone
}


resource "google_compute_instance" "main" {
 name                      = "${var.env}-main-server"
 machine_type              = "custom-2-4096"
 zone                      = var.zone
 allow_stopping_for_update = true
 desired_status            = "RUNNING"
 deletion_protection       = true
 tags                      = ["${var.env}-main-server"]

 boot_disk {
   auto_delete = false

   mode = "READ_WRITE"
   initialize_params {
     image = "debian-cloud/debian-10"
     type  = "pd-ssd"
     size  = 20
   }
 }

 network_interface {
   network    = var.network_id
   subnetwork = var.subnetwork_id
   network_ip = google_compute_address.main_server_internal.address

   access_config {
     nat_ip = google_compute_address.main_server_external.address
   }
 }
 scheduling {
   on_host_maintenance = "MIGRATE"
   automatic_restart   = true
 }

 lifecycle {
   ignore_changes = [attached_disk]
 }
}


resource "google_compute_attached_disk" "fast_storage" {
 disk        = google_compute_disk.fast_storage.id
 instance    = google_compute_instance.main.id
 device_name = "fast"
 mode        = "READ_WRITE"
}

設置guest_flush = false(這僅適用於 Windows,並且看起來與 gcp 不可協商。

檢查 Stackdriver 日誌 - 磁碟

引用自:https://serverfault.com/questions/1031951