我想解决尝试从Amazon Simple Storage Service(Amazon S3)恢复我的 Amazon ElastiCache 集群时发生的“创建失败”或“权限被拒绝”错误。
简短描述
以下是从 Amazon S3 还原 ElastiCache 备份失败的常见原因:
- 您试图在备份限制之外恢复备份。
- ElastiCache 无法从 Amazon S3 检索文件。
- ElastiCache 备份文件位于另一个 AWS 区域的 Amazon S3 存储桶中。
- 您可以将包含多个数据库的 rdb 文件恢复到已开启集群模式的 ElastiCache 集群中。
解决方法
您尝试在备份限制之外恢复备份
在恢复 ElastiCache for Redis 备份时,请务必了解备份限制:
- 您无法从使用开启集群模式的 Redis 集群的备份恢复到已关闭集群模式的 Redis 集群。
- 当您从开启集群模式的 ElastiCache 集群恢复备份时,您无法在 ElastiCache 控制台中关闭集群模式。仅可用开启集群模式的选项。
- 当您将带有已开启集群模式的 ElastiCache 集群的备份导出到 Amazon S3 时,会创建多个 rdb 文件。如果您使用一个备份 rdb 文件为 Amazon S3 的备份填充数据,则只有一个分片的键会填充到集群。如果您尝试使用通配符***rdb** 文件来解决这个问题,则会出现以下错误。
"Error: Object or bucket does not exist for S3 object: examplebucket/cluster-mode-enabled-*.rdb."
- 您无法从使用数据分层的集群恢复备份。例如,您无法将 r6gd 节点恢复到不使用数据分层的集群中。
- 您无法将数据分层备份导出到 Amazon S3。此外,你无法从 Amazon S3 恢复 ElastiCache 数据分层备份。有关更多信息,请参阅 Limitations。
- 对于具有多个数据库的 rdb 文件,您无法从 Redis(已关闭集群模式)集群恢复到 Redis(已开启集群模式)集群。当您尝试执行此操作时,会出现以下错误:
"Error: To restore a snapshot in cluster mode, all keys in the RDB file should reside in DB 0."
ElastiCache 无法从 Amazon S3 检索文件
如果 ElastiCache 没有访问存储在 Amazon S3 存储桶中的 ElastiCache 备份所需的权限,则会出现以下错误:
"Restore from snapshot failed for node group 0001 in replication group test.Failed to retrieve file from S3."
要确认权限问题,请查看您的 ElastiCache 事件。确定错误原因后,请检查您所在的地区是否为以下地区之一:
- 可选区域
- 中国(北京)和中国(宁夏)
- AWS GovCloud(美国西部)
- 默认区域
对于可选区域,您必须制定允许 ElastiCache 从 Amazon S3 检索备份文件的存储桶政策。
如果您的 Amazon S3 存储桶位于以下区域之一,则必须允许 ElastiCache 服务访问 S3 中的备份文件:
- 中国(北京)和中国(宁夏)
- AWS GovCloud(美国西部)
- 默认区域
**注意:**中国(北京)、中国(宁夏)和 AWS GovCloud(美国西部)区域的规范 ID 与默认 AWS 区域不同:
- 中国(北京)和中国(宁夏):b14d6a125bdf69854ed8ef2e71d8a20b7c490f252229b806e514966e490b8d83
- AWS GovCloud(美国西部):40fa568277ad703bd160f66ae4f83fc9dfdfd06c2f1b5060ca22442ac3ef8be6
- AWS 默认区域:540804c33a284a299d2547575ce1010f2312ef3da9b3a053c8bc45bf233e4353
当您使用规范 ID 或存储桶策略授予对 rdb 备份对象的 ElastiCache 访问权限时,请恢复 Redis 集群。
ElastiCache 备份文件位于另一个区域的 Amazon S3 存储桶中
如果您尝试恢复位于另一个地区的 Amazon S3 存储桶中的 ElastiCache 备份,则会出现以下错误:
"Permission denied to access S3 object.Please use the S3 object in the same region."
要解决此错误,请完成下面的步骤:
**注意:**如果在运行 AWS 命令行界面(AWS CLI)命令时收到错误,请参阅 Troubleshoot AWS CLI errors。此外,确保您使用的是最新版本的 AWS CLI。
-
使用以下命令从 Amazon S3 存储桶复制 rdb 备份文件。确保存储桶包含要恢复 Redis 集群的区域中的备份。有关更多信息,请参阅 迁移 ElastiCache for Redis 集群的最佳实践是什么?
注意:使用相应的名称替换 example-source-bucket、example-destination-bucket、example-backup、example-source-region 和 example destination-region。
aws s3 cp s3://example-source-bucket/example-backup.rdb s3://example-destination-bucket/example-backup.rdb --acl bucket-owner-full-control --source-region example-source-region --region example-destination-region
-
确认 rdb 备份文件分配了正确的权限(规范 ID 或存储桶策略)。
-
继续恢复集群。
将包含多个数据库的 rdb 文件恢复到已开启集群模式的 ElastiCache 集群中
如果您将包含多个数据库的 rdb 文件恢复到开启集群模式的 ElastiCache 集群,则会出现以下错误:
"Restore from snapshot failed for node group 0001 in replication group test.To restore a snapshot in cluster mode, all keys in the RDB file should reside in DB 0.Snapshot ID: arn:aws:s3:::example-bucket/multidb.rdb"
要检查还原失败的原因,请查看您的 ElastiCache 事件。
要解决此错误,请完成下面的步骤:
- 确保将所有键迁移到单个数据库。有关更多信息,请参阅在 Redis 网站上的Migrate。
**注意:**如果源数据库位于 ElastiCache Redis 上,则不支持迁移命令。要解决此问题,请使用其他 Redis 工具,例如 RIOT。有关更多信息,请参阅 Redis 网站上的 riot 。
- 创建 Redis 数据库的本地备份。
- 将备份上传到 Amazon S3。
- 继续恢复到 ElastiCache(已开启集群模式)集群。