
GCP で Terraform を使用して VM を作成し、google_compute_disk、google_compute_resource_policy、google_compute_disk_resource_policy_attachment リソースを使用して永続ディスクを別途作成し、ディスクにスナップショット スケジュールもアタッチしました。
これは 2 日前のことで、スナップショットは作成されていません。
同様の問題に遭遇した人はいますか?
スケジュールは毎日に設定されています。
これは私が使用した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
enabled = true
sudo systemctl restart google-guest-agent.service
/etc/google/snapshots
- 作成する前そして役職スナップショットスクリプトをそれぞれ
/etc/google/snapshots/pre.sh
とに/etc/google/snapshots/post.sh
作成します。スクリプトが実行可能ルート権限を取得する(ドキュメントには明記されていないが、簡単に理解できる) - ゲスト フラッシュを有効にしてスナップショット (またはスナップショット スケジュール) を作成します。
GCP で動作していることを確認しました。
上記の説明に従って VM インスタンスを準備していない場合、アプリケーション整合性スナップショットを作成しようとすると、以下のようなエラーが発生します。
- 上記 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"
つまり、上で説明したように VM を準備していないということです。