管理备份

本页介绍了如何执行 Memorystore for Valkey 备份操作。在阅读本页内容之前,请确保您熟悉备份

准备工作

  1. 确保您或您正在使用的用户账号拥有所需的操作权限

    Memorystore 管理员Memorystore 编辑器角色可以执行所有备份操作。Memorystore Viewer 角色可以查看和导出备份。

  2. 安装并更新 Google Cloud CLI

创建按需备份

如需创建按需备份,请使用 gcloud memorystore instances backup 命令。

gcloud

gcloud memorystore instances backup INSTANCE_ID \
--backup-id=BACKUP_ID \
--ttl=TTL_PERIOD

替换以下内容:

  • INSTANCE_ID:Memorystore for Valkey 实例的 ID。
  • BACKUP_ID:备份的 ID,例如 march-2025-backup
  • TTL_PERIOD:备份的存留时间 (TTL)。备份达到 TTL 限制后,Memorystore for Valkey 会自动删除该备份。

    您可以将此参数的值设置为天数(例如 14d)。最小值为 1 天。如果未指定值,则默认值为 100 年。

该命令会返回以下格式的操作名称:

projects/PROJECT_ID/locations/REGION_ID/operations/operation-UID

如需检查操作的状态,请使用 gcloud memorystore operations describe 命令。

gcloud memorystore operations describe projects/PROJECT_ID/locations/REGION_ID/operations/operation-UID

如需列出项目和区域中的所有操作,请使用 gcloud memorystore operations list 命令。

gcloud memorystore operations list --projects=PROJECT_ID \
--location=REGION_ID

配置自动备份时间表

您可以在创建实例时配置每日备份时间表,也可以为现有实例启用每日备份时间表。

创建启用了自动备份时间表的实例

以下示例演示了如何在创建实例时设置每日备份时间表。如需了解创建实例时可用的更多选项,请参阅创建实例

gcloud

gcloud memorystore instances create INSTANCE_ID \
--automated-backup-mode=ENABLED \
--automated-backup-start-time=START_TIME \
--automated-backup-ttl=RETENTION_POLICY

替换以下内容:

  • INSTANCE_ID:您要创建的 Memorystore for Valkey 实例的 ID。
  • START_TIME:Memorystore for Valkey 开始进行备份的时间。以 HH 格式指定世界协调时间 (UTC) 的 24 小时制时间。例如:23
  • RETENTION_POLICY:Memorystore for Valkey 保留每个备份的天数。将此参数的值设置为天数(例如 7d)。最大值为 365 天,默认值为 35 天。

    即使您删除实例,Memorystore for Valkey 也会在保留期限内保留备份(最长 365 天)。如需在保留期限结束前移除备份,您必须手动删除备份

在现有实例上启用定期备份

如需在实例上启用定期备份,请使用 gcloud memorystore instances update 命令。

gcloud

gcloud memorystore instances update INSTANCE_ID \
--automated-backup-mode=enabled \
--automated-backup-start-time=START_TIME \
--automated-backup-ttl=RETENTION_POLICY

替换以下内容:

  • INSTANCE_ID:要更新的 Memorystore for Valkey 实例的 ID。
  • START_TIME:一个时间戳,用于指定 Memorystore for Valkey 开始进行备份的时间。此时间戳必须采用 HH 格式,以小时为单位,并采用 24 小时制 UTC 时间(例如 23)。此时间戳还指定了 Memorystore for Valkey 开始进行备份的一小时时段。
  • RETENTION_POLICY:Memorystore for Valkey 保留每个备份的天数。将此参数的值设置为天数(例如 7d)。

    即使您删除实例,Memorystore for Valkey 也会在保留期限内保留该备份。如需在保留期限到期之前移除备份,您必须手动删除备份

在现有实例上停用定期备份

如需停用实例上的定期备份,请使用 gcloud memorystore instances update 命令。

gcloud

gcloud memorystore instances update INSTANCE_ID \
--automated-backup-mode=disabled

INSTANCE_ID 替换为您要更新的 Memorystore for Valkey 实例的 ID。

与更新实例、维护和备份操作的并发

在以下情况下,实例的更新操作和维护操作可能会取消正在进行的备份操作:

  • 如果正在进行实例更新操作,Memorystore for Valkey 会拒绝备份操作请求。
  • 如果有正在进行的备份操作,Memorystore for Valkey 会拒绝传入的用于更新实例的操作。
  • 维护和备份操作可能会重叠。如果发生这种情况,Memorystore for Valkey 会跳过该实例的备份操作。

列出和描述备份

以下部分演示了如何查找备份相关信息。

列出备份集合

备份集合包含 Memorystore for Valkey 实例的所有备份。如需列出项目和区域的备份集合,请使用 gcloud memorystore backup-collections list 命令。

gcloud

gcloud memorystore backup-collections list \
--project=PROJECT_ID \
--location=REGION_ID

替换以下内容:

  • PROJECT_ID:您的项目 ID
  • REGION_ID:实例所在的区域(例如 us-east1

该命令会返回备份集合列表。

列出备份集合中的备份

如需列出备份集合中的备份,请使用 gcloud memorystore backup-collections backups list 命令。

gcloud

gcloud memorystore backup-collections backups list \
--backup-collection=BACKUP_COLLECTION
--project=PROJECT_ID \
--location=REGION_ID

替换以下内容:

  • BACKUP_COLLECTION:备份集合的名称
  • PROJECT_ID:您的项目 ID
  • REGION_ID:实例所在的区域(例如 us-east1

该命令会返回备份集合中的备份列表。

描述备份

如需检索备份的相关信息,请使用 gcloud memorystore backup-collections backups describe 命令。

gcloud

gcloud memorystore backup-collections backups describe BACKUP_NAME \
--backup-collection=BACKUP_COLLECTION \
--project=PROJECT_ID \
--location=REGION_ID

替换以下内容:

  • BACKUP_NAME:备份的名称(例如 2024-05-01-10-15-00
  • BACKUP_COLLECTION:备份集合的名称
  • PROJECT_ID:您的项目 ID
  • REGION_ID:实例所在的区域(例如 us-east1

该命令会返回类似于以下内容的备份相关信息:

backupFiles:
- createTime: '2024-11-10T03:52:55.539Z'
fileName: 3d2774dab822137c5bac9386f3fa69ee4c73b928.rdb
sizeBytes: '694879680'
- createTime: '2024-11-10T03:52:54.742Z'
fileName: 7f5d99faaefc63ed8292a71da2552db3b06cdcff.rdb
sizeBytes: '694925906'
- createTime: '2024-11-10T03:52:54.972Z'
fileName: 0aac1092a3fb81515aefb6b2421f31eb346c3961.rdb
sizeBytes: '694784169'
instance: projects/PROJECT_ID/locations/us-east1/instances/instance1
instanceUid: 57130520-636c-4ac7-ad7e-86f7cfb32838
createTime: '2024-11-10T03:52:40.899882388Z'
expireTime: '2124-11-10T03:53:02.856981736Z'
name: projects/PROJECT_ID/locations/us-east1/backupCollections/dda2f551-b416-47ff-b1cf-684e00483dc9/backups/march-2025-backup
nodeType: HIGHMEM_MEDIUM
shardCount: 3
state: ACTIVE
totalSizeBytes: '2084589755'

删除备份

如需删除备份,请使用 gcloud memorystore backup-collections backups delete 命令。

gcloud

gcloud memorystore backup-collections backups delete BACKUP_NAME \
--backup-collection=BACKUP_COLLECTION \
--project=PROJECT_ID \
--location=REGION_ID

替换以下内容:

  • BACKUP_NAME:备份的名称(例如 2024-05-01-10-15-00
  • BACKUP_COLLECTION:备份集合的名称
  • PROJECT_ID:您的项目 ID
  • REGION_ID:实例所在的区域(例如 us-east1

将备份导出到存储分区

您可以将备份导出到 Cloud Storage 存储分区。

以下步骤演示了如何导出备份。

  1. 向 Memorystore for Valkey 服务代理授予对 Cloud Storage 资源的访问权限。

    您需要向服务代理授予对 Cloud Storage 资源的访问权限,以便 Memorystore for Valkey 能够访问目标 Cloud Storage 存储分区。此外,Memorystore for Valkey 服务代理使用以下命名格式:

    service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com
    

    PROJECT_NUMBER 替换为实例或备份所在项目的项目编号

    向服务代理授予一个角色,并向该角色分配 storage.buckets.getstorage.objects.createstorage.objects.deletestorage.folders.create 权限。

    例如,以下命令会将 Storage Admin 角色分配给 Cloud Storage 存储分区的服务代理:

    gcloud

    gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME \
    --member=serviceAccount:service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com \
    --role=roles/storage.admin
    

    替换以下内容:

    • BUCKET_NAME:目标 Cloud Storage 存储分区的名称。此存储分区必须是区域存储分区,并且必须与备份位于同一区域。Memorystore for Valkey 必须有权访问存储分区以及在存储分区中创建文件夹和对象。
    • PROJECT_NUMBER:服务代理名称中使用的项目编号。
  2. 如需将备份导出到 Cloud Storage 存储分区,请使用 gcloud memorystore backup-collections backups export 命令。

    gcloud

    gcloud memorystore backup-collections backups export BACKUP_NAME \
    --backup-collection=BACKUP_COLLECTION \
    --location=REGION_ID \
    --gcs-bucket=BUCKET_NAME
    

    替换以下内容:

    • BACKUP_NAME:Memorystore for Valkey 备份的名称
    • BACKUP_COLLECTION:备份集合的名称
    • REGION_ID:备份集合所在的区域(例如 us-east1
    • BUCKET_NAME:Cloud Storage 存储分区的名称

从备份恢复数据

如需从备份恢复数据,您可以从同一项目中的托管式备份为新实例进行种子化,也可以从 Cloud Storage 存储分区中的 RDB 文件为新实例进行种子化。如需从 RDB 文件中为实例进行种子化,Memorystore for Valkey 必须拥有访问这些文件的权限。

基于备份为新实例提供种子

以下示例演示了如何将数据从备份导入到新实例。备份必须与实例位于同一区域。此外,创建实例的正文必须对备份拥有 redis.backups.get 权限。

gcloud

gcloud memorystore instances create INSTANCE_ID \
--import-managed-backup=BACKUP_NAME \
--location=REGION_ID

替换以下内容:

  • INSTANCE_ID:您要创建的 Memorystore for Valkey 实例的 ID。
  • BACKUP_NAME:备份的名称。此名称的格式如下:projects/PROJECT_ID/locations/REGION_ID/backupCollections/BACKUP_COLLECTION_ID/backups/BACKUP_ID
  • REGION_ID:实例所在的区域(例如 us-east1)。

从存储分区中的 RDB 文件为新实例设置种子

您可以将数据从 Cloud Storage 存储分区中包含的 RDB 文件导入到新实例。

以下步骤演示了如何将数据从 Cloud Storage 存储分区中的 RDB 文件导入到新实例。

  1. 向 Memorystore for Valkey 服务代理授予对 Cloud Storage 资源的访问权限。

    您需要向 Service Agent 授予对 Cloud Storage 资源的访问权限,以便 Memorystore for Valkey 可以访问 Cloud Storage 存储分区中的 RDB 文件。此外,Memorystore for Valkey 服务代理使用以下命名格式:

    service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com

    PROJECT_NUMBER 替换为您创建新实例的项目的项目编号

    向服务代理授予一个角色,并向该角色分配 storage.buckets.getstorage.objects.get 权限。

    例如,以下命令会将 Storage Admin 角色分配给 Cloud Storage 存储分区的服务代理:

    gcloud

    gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME
    --member=serviceAccount:service-PROJECT_NUMBER@gcp-sa-memorystore.iam.gserviceaccount.com
    --role=roles/storage.admin
    

    替换以下内容:

    • BUCKET_NAME:RDB 文件所在的存储分区的名称。此存储分区必须是与备份位于同一区域的单区域存储分区,或者是双区域存储分区,且其中一个区域与备份位于同一区域。Memorystore for Valkey 必须具有访问该存储分区的权限。
    • PROJECT_NUMBER:服务代理名称中使用的项目编号。
  2. 如需将 Cloud Storage 存储分区中的 RDB 文件中的数据导入到新实例,请使用 gcloud memorystore instances create 命令。

    gcloud

    gcloud memorystore instances create INSTANCE_ID \
    --import-gcs-object-uris=URI \
    --location=REGION_ID
    

    替换以下内容:

    • INSTANCE_ID:您要创建的 Memorystore for Valkey 实例的 ID。
    • URI:一个或多个以英文逗号分隔的 Cloud Storage 统一资源标识符 (URI)。例如:gs://my-bucket/folder/file1.rdb,gs://my-bucket/folder/file2.rdb
    • REGION_ID:实例所在的区域(例如 us-east1)。

Cloud Monitoring 指标

如需监控近期的备份和导入操作,您可以使用 Cloud Monitoring 指标。如需查看 Memorystore for Valkey 备份可用的指标列表,请参阅备份指标