Google Cloud Compute Engine 持久磁盘快照计划不起作用

Google Cloud Compute Engine 持久磁盘快照计划不起作用

我在 GCP 上使用 terraform 创建了一个虚拟机,还分别使用 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"
}

答案1

设置guest_flush = false(这仅适用于 Windows,并且看起来与 gcp 不可协商。

检查 Stackdriver 日志 - 磁盘

答案2

这只适用于 Windows,并且看起来与 gcp 无法协商

这是不对。请关注文章创建 Linux 应用程序一致的持久磁盘快照其中解释了什么是必要的,基本上是:

  1. [Snapshots]部分添加到/etc/default/instance_configs.cfgenabled = true使用重新启动代理。如果目录尚不存在,sudo systemctl restart google-guest-agent.service最后一个命令将创建目录;/etc/google/snapshots
  2. 创造邮政快照脚本分别位于/etc/google/snapshots/pre.sh/etc/google/snapshots/post.sh。确保脚本可执行文件到 root(这在文档中没有明确说明,但很容易弄清楚);并且
  3. 创建启用了 guest-flush 的快照(或快照计划)。

刚刚验证了它在 GCP 中可以正常工作。

如果您尚未按照上述说明准备好虚拟机实例,则在尝试创建应用程序一致性快照时会遇到如下错误:

  • 如果上述1.没有完成:Operation type [createSnapshot] failed with message "You can only use guest-flush on disks attached to instances with supported operating systems. Make sure you have the latest image version and agent installed with required services (e.g. VSS for Windows)."
  • 如果上述第 2 点未完成:Operation type [createSnapshot] failed with message "Guest Consistent Snapshot failed (Detail: pre_snapshot_script or post_snapshot_script not found). Verify you are running the latest image version and agent. For non-Windows, review settings in /etc/default/instance_configs.cfg on the instance. For more information, see the Guest Consistent Snapshot documentation."或者如果脚本未变为可执行文件,则执行以下操作:Operation type [createSnapshot] failed with message "Guest Consistent Snapshot failed (Detail: unhandled script return code -1). Verify you are running the latest image version and agent. For non-Windows, review settings in /etc/default/instance_configs.cfg on the instance. For more information, see the Guest Consistent Snapshot documentation."

如果您的快照计划未生成快照,请检查You can only use guest-flush on disks attached to instances with supported operating systems. Make sure you have the latest image version and agent installed with required services (e.g. VSS for Windows).日志资源管理器中的错误,可以使用以下查询轻松找到这些错误

severity=ERROR`
resource.type="gce_disk"
protoPayload.methodName="ScheduledSnapshots"

我的意思是您还没有像上面解释的那样准备好您的虚拟机。

相关内容