
我在 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 應用程式一致的永久磁碟快照其中解釋了必要的內容,基本上是:
- 將
[Snapshots]
部分新增至/etc/default/instance_configs.cfg
withenabled = true
並使用 重新啟動代理程式sudo systemctl restart google-guest-agent.service
。/etc/google/snapshots
如果目錄尚不存在,最後一個指令將建立目錄; - 創造前和郵政快照腳本分別位於
/etc/google/snapshots/pre.sh
和/etc/google/snapshots/post.sh
。確保腳本是執行檔root(這在文件中沒有明確說明,但很容易弄清楚);和 - 建立啟用 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"
我的意思是你還沒有像上面解釋的那樣準備好你的虛擬機器。