为归档资源创建和管理备份方案

概览

本页面介绍了如何为保险库资源创建和管理备份方案。如需了解备份方案的含义及其使用方式,请参阅 Google Cloud 控制台中的备份方案

准备工作

如需获得创建和管理备份方案所需的权限,请让您的管理员为您授予备份保险库项目的 Backup and DR User V2 (roles/backupdr.userv2) IAM 角色。 如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

此预定义角色包含创建和管理备份方案所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

如需创建和管理备份方案,需要具备以下权限:

  • backupdr.backupPlans.create
  • backupdr.backupPlans.list
  • backupdr.backupPlans.get
  • backupdr.backupPlans.delete
  • backupdr.backupVaults.associate

您也可以使用自定义角色或其他预定义角色来获取这些权限。

如需了解如何授予用户在给定项目中应用备份方案的权限(但不能创建备份方案),请参阅备份用户的 IAM 角色和权限

创建备份方案

按照以下说明为保险库资源创建备份方案。

控制台

  1. 在 Google Cloud 控制台中,前往备份方案页面。

    前往“备份方案”

  2. 点击创建备份方案

  3. 对于资源类型,请选择以下任一选项:

    • Compute Engine:适用于 Compute Engine 实例
    • 磁盘:适用于挂接到 Compute Engine 实例的磁盘。
    • Cloud SQL:适用于 Cloud SQL 实例(预览版)。
  4. 备份方案名称字段中,输入备份方案的名称。备份方案创建后,您无法更改方案的名称。

  5. 备份方案说明字段中,输入备份方案的可选说明。

  6. 区域列表中,选择备份方案区域。备份方案是在此区域中创建的。您可以保护与备份方案位于同一区域的资源。

  7. 备份保险柜列表中,选择用于存储备份的备份保险柜。

  8. 添加备份规则部分中,默认备份规则已就位。

    1. 如果您想使用此规则,并且不使用其他备份规则,可以继续配置数据库日志备份
    2. 如果您想添加一项或多项额外的备份规则,请点击添加规则
    3. 添加备份规则窗格中,输入备份规则信息,然后点击保存

      • 为备份规则命名:为备份规则输入一个名称。
      • 选择创建备份的时间:指定备份的周期和频率。
      • 时间段:为备份作业选择时区开始时间结束时间
      • 选择将备份保留多久后删除:输入备份在删除之前应保留的天数。请注意,此值必须等于或大于备份保险柜强制保留期限下限
  9. 如果您要保护数据库实例,系统会显示配置数据库日志备份。您可以使用预写式日志归档功能,从特定时间点恢复数据,时间可精确到零点几秒。设置后即无法更改。勾选相应复选框,然后选择数据库日志的保留时长。

  10. 点击创建

gcloud

  1. 为 Compute Engine 实例创建每小时备份一次的备份方案。

      gcloud backup-dr backup-plans create BACKUP_PLAN_NAME \
      --project=PROJECT_ID \
      --location=LOCATION \
      --resource-type=RESOURCE_TYPE \
      --backup-vault BACKUPVAULT_NAME \
      --backup-rule rule-id=RULE_NAME,retention-days=BACKUP_RETENTION,recurrence=RECURRENCE,hourly-frequency=HOURS,time-zone=TIME_ZONE,backup-window-start=START_TIME,backup-window-end=END_TIME
    

    替换以下内容:

    + `BACKUP_PLAN_NAME`: the name of the backup plan.
    + `PROJECT_ID`: the name of the project where you
    want to create the backup plan.
    + `RESOURCE_TYPE`: the resource type to be protected
    by the backup plan. Values are: `compute.googleapis.com/Instance`, `compute.googleapis.com/Disk`, `sqladmin.googleapis.com/Instance`.
    + `LOCATION`: the location where you want to create
    the backup plan.
    + `BACKUPVAULT_NAME`: the name of the
     backup vault that you want to use for backup storage.
    + `RULE_NAME`: the name of the backup rule.
    + `BACKUP_RETENTION`: the retention period of the
    backup. Note that the backup retention period must be equal to or
    greater than the backup vault enforced minimum retention
    period.
    + `RECURRENCE`: the frequency at which backups to
    be created. It can be hourly, daily, weekly, monthly, or yearly.
    + `HOURS`: the frequency of the hourly backups.
    Specify this value only if you set the recurrence to hourly.
    The minimum hourly is always set to six hours.
    + `TIME_ZONE`: the time zone for the backup plan,
    such as UTC. Use the
    [IANA time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
    format to include the timezone for the backup plan.
    + `START_TIME`: the start time is the hour of the
    day in a 24 hour format. The start time must be before the end time
    and is inclusive for the backup window.
    + `END_TIME`: the end time is the hour of the day
    in a 24 hour format. The end time must be after the start time and
    is exclusive for the backup window.
    

    示例:每 6 小时备份一次 Compute Engine 实例,并将备份存储 11 天。

      gcloud backup-dr backup-plans create bp-hourly \
      --project=test-project --location=us-central1 \
      --resource-type=compute.googleapis.com/Instance \
      --backup-vault=test-bv \
      --backup-rule=rule-id=rule-hourly,recurrence=HOURLY,hourly-frequency=6,backup-window-start=5,backup-window-end=12,retention-days=11
    

    示例:每天上午 5 点到中午 12 点之间备份磁盘,并将备份存储 12 天。

      gcloud backup-dr backup-plans create bp-daily \
      --project=test-project --location=us-central1 \
      --resource-type=compute.googleapis.com/Disk \
      --backup-vault=test-bv \
      --backup-rule=rule-id=rule-daily,recurrence=DAILY,backup-window-start=5,backup-window-end=12,retention-days=12
    

    示例:在周一和周三上午 5 点到中午 12 点之间备份 Compute Engine 实例,并将备份存储 13 天。

      gcloud backup-dr backup-plans create bp-weekly \
      --project=test-project --location=us-central1 \
      --resource-type=compute.googleapis.com/Instance \
      --backup-vault=test-bv \
      --backup-rule=rule-id=rule-weekly,recurrence=WEEKLY,days-of-week='MON WED',backup-window-start=5,backup-window-end=12,retention-days=13
    

    示例:在每个月的 1 日和 15 日上午 5 点到中午 12 点之间备份磁盘,并将备份存储 14 天。

      gcloud backup-dr backup-plans create bp-monthly \
      --project=test-project --location=us-central1 \
      --resource-type=compute.googleapis.com/Disk \
      --backup-vault=test-bv \
      --backup-rule=rule-id=rule-monthly,recurrence=MONTHLY,days-of-month='1 15',backup-window-start=5,backup-window-end=12,retention-days=14
    

    示例:在每年 3 月、6 月、9 月、12 月的 10 日、20 日、30 日备份 Compute Engine 实例,并将备份存储 16 天。

      gcloud backup-dr backup-plans create bp-yearly \
      --project=test-project --location=us-central1 \
      --resource-type=compute.googleapis.com/Instance \
      --backup-vault=test-bv \
      --backup-rule=rule-id=rule-yearly,recurrence=YEARLY,months='MAR JUN SEP DEC',days-of-month='10 20 30',backup-window-start=5,backup-window-end=12,retention-days=16
    

Terraform

您可以使用 Terraform 资源创建备份计划,并设置每小时、每天、每周、每月或每年的备份频率。


# Before creating a backup plan, you need to create backup vault (google_backup_dr_backup_vault).
resource "google_backup_dr_backup_plan" "default" {
  provider       = google-beta
  location       = "us-central1"
  backup_plan_id = "my-bp"
  resource_type  = "compute.googleapis.com/Instance"
  backup_vault   = google_backup_dr_backup_vault.default.name

  backup_rules {
    rule_id               = "rule-1"
    backup_retention_days = 5

    standard_schedule {
      recurrence_type  = "HOURLY"
      hourly_frequency = 6
      time_zone        = "UTC"

      backup_window {
        start_hour_of_day = 0
        end_hour_of_day   = 24
      }
    }
  }
}

列出备份方案

请按照以下说明列出备份方案。

控制台

  1. 在 Google Cloud 控制台中,前往备份方案页面。

    前往“备份方案”

    备份方案页面列出了项目中的所有备份方案。

gcloud

  1. 列出备份方案。

      gcloud backup-dr backup-plans list \
      --location=LOCATION \
      --project=PROJECT_ID
    

    替换以下内容:

    • LOCATION:备份方案的位置。
    • PROJECT_ID:创建备份方案的项目的名称。

查看备份方案详情

按照以下说明查看备份方案详细信息。

控制台

  1. 在 Google Cloud 控制台中,前往备份方案页面。

    前往“备份方案”

  2. 在备份方案列表中,点击要查看的备份方案的名称。

    备份方案详细信息会显示以下信息:

    • 资源类型
    • 备份方案详情
    • 备份保险柜名称
    • 备份存储位置
    • 备份保留期限

gcloud

  1. 查看备份方案详情。

      gcloud backup-dr backup-plans describe BACKUP_PLAN_NAME \
      --location=LOCATION \
      --project=PROJECT_ID
    

    替换以下内容:

    • BACKUP_PLAN_NAME:备份方案的名称。
    • LOCATION:备份方案的位置。
    • PROJECT_ID:创建备份方案的项目名称。

删除备份方案

如果您正在使用备份方案来保护资源,则无法删除该方案。如需删除备份方案,请先从资源中移除该备份方案,然后再将其删除。

删除备份方案时:

  • 应用方案时已经创建的备份不受影响。备份会在其保留期限到期后过期,过期前可访问备份。
  • 任何引用该方案的自动操作都将失效。

按照以下说明删除备份方案。

控制台

  1. 在 Google Cloud 控制台中,前往备份方案页面。

    前往“备份方案”

  2. 点击要删除的备份方案。

  3. 点击删除

  4. 在随即显示的叠加窗口中,确认要删除备份方案及其内容。

  5. 点击删除

gcloud

  1. 删除备份方案。

      gcloud backup-dr backup-plans delete BACKUP_PLAN_NAME \
      --location=LOCATION \
      --project=PROJECT_ID
    

    替换以下内容:

    • BACKUP_PLAN_NAME:您要删除的备份方案的名称。
    • LOCATION:备份方案的位置。
    • PROJECT_ID:创建备份方案的项目名称。

后续步骤