还原到某个时间点
使用 AWS 管理控制台或 AWS Command Line Interface (AWS CLI) 可将集群还原到该集群的备份保留期内的任何时间点。
注意
您不能将 3.6 集群的时间点还原到 4.0 集群,但可以从一个集群版本迁移到另一个集群版本。有关更多信息,请转至 迁移到 Amazon DocumentDB。
在将集群还原至某个时间点时,请牢记以下几点。
- 创建新集群时将使用与源集群相同的配置,区别在于创建新集群时将使用默认参数组。要将新集群的参数组设置为源集群的参数组,请在新集群可用 后对其进行修改。有关修改集群的更多信息,请参阅修改 Amazon DocumentDB集群。
使用 AWS 管理控制台还原到时间点
可以使用 AWS 管理控制台完成以下操作,以将集群还原到该集群的备份保留期内的某个时间点。
- 通过以下网址登录 AWS 管理控制台并打开 Amazon DocumentDB 控制台:https://console.aws.amazon.com/docdb。
- 在导航窗格中,选择 Clusters。在集群列表中,选择要还原的集群左侧的按钮。
提示
如果您在屏幕左侧没有看到导航窗格,请在页面左上角选择菜单图标 (
)。
3. 在 Actions (操作) 菜单上,选择 Restore to point in time (还原到时间点)。
4. 完成 Restore time (恢复时间) 部分,用于指定将还原到的日期和时间。
- Restore date (还原日期) — 选择或输入的日期介于 Earliest restore time (最早还原时间) 和 Latest restore time (最新还原时间) 之间。
- Restore time (还原时间) — 选择或输入介于 Earliest restore time (最早还原时间) 和 Latest restore time (最新还原时间) 之间的小时、分钟和秒。
-
填写 Configuration (配置) 部分。
-
Cluster identifier (集群标识符) — 接受默认标识符,或者输入您喜欢的标识符。
集群命名约束:
- 长度为 [1—63] 个字母、数字或连字符。
- 第一个字符必须是字母。
- 不能以连字符结束或包含两个连续连字符。
- 对于每个区域的每个 AWS 账户的所有集群(在 Amazon RDS、Neptune 和 Amazon DocumentDB 中)必须是唯一的。 2. Instance class (实例类) — 从下拉列表中,选择要用于集群实例的实例类。 3. Number of instances (实例数) — 从下拉列表中,选择还原此集群时您希望创建的实例的数量。 6. 可选。要配置网络设置、集群选项和启用日志导出,请选择 Show advanced settings (显示高级设置),然后完成以下各部分。否则,请继续下一步。
-
Network settings (网络设置)
- Virtual Private Cloud (VPC) — 从下拉列表中,选择要用于此集群的 VPC。
- Subnet group (子网组) — 从下拉列表中,为此集群选择子网组。
-
VPC security groups (VPC 安全组) — 从下拉列表中,为此集群选择 VPC 安全组。 - Cluster options (集群选项)
-
Port (端口) — 接受默认端口 (27017),或者使用向上或向下箭头来设置此集群进行通信的端口。 - 日志导出
-
Audit logs (审计日志) — 选择此选项可启用将审计日志导出到 Amazon CloudWatch Logs 的功能。如果您选择此选项,则必须在集群的自定义参数组中启用
audit_logs。有关更多信息,请参阅审核 Amazon DocumentDB 事件。 -
Profiler logs (分析器日志) — 选择此选项可启用将操作分析器日志导出到 Amazon CloudWatch Logs 的功能。如果您选择此选项,还必须在集群的自定义参数组中修改以下参数:
profiler— 设置为enabled。profiler_threshold_ms— 设置为[0-INT_MAX]之间的值,以设置分析操作的阈值。profiler_sampling_rate— 设置为[0.0-1.0]之间的值,以设置要分析的缓慢操作的百分比。
有关更多信息,请参阅Profiling Amazon DocumentDB Operations。 3. Profiler logs (分析器日志) — 将分析器日志导出到 AmazonCloudWatch 4. IAM role (IAM 角色) — 从下拉列表中,选择 RDS Service Linked Role (服务相关角色)。 - Tags
-
Add Tag (添加标签) — 在 Key (密钥) 框中,输入集群标签的名称。在 Value (值) 框中,可以选择输入标签值。标签与 AWS Identity and Access Management (IAM) 策略结合使用,以管理对 Amazon DocumentDB 资源的访问并控制可将什么操作应用于资源。 - 删除保护
-
Enable deletion protection (启用删除保护) — 防止集群被意外删除。启用该选项后,您将无法删除集群。
- 要还原集群,请选择 Create cluster (创建集群)。或者,您可以选择 Cancel (取消) 以取消操作。
使用 AWS CLI 还原到时间点
要使用快照的备份保留期将集群还原到某个时间点,请使用带有以下参数的 restore-db-cluster-to-point-in-time 操作。
--db-cluster-identifier— 必需。要创建的新集群的名称。在执行该操作之前,不能存在此集群。参数值必须满足以下约束。
集群命名约束:
- 长度为 [1—63] 个字母、数字或连字符。
- 第一个字符必须是字母。
- 不能以连字符结束或包含两个连续连字符。
- 对于每个区域的每个 AWS 账户的所有集群(在 Amazon RDS、Neptune 和 Amazon DocumentDB 中)必须是唯一的。
--restore-to-time— 要将集群还原到的 UTC 日期和时间。例如:2018-06-07T23:45:00Z。
时间约束:
- 必须在集群的最新可还原时间之前。
- 如果未提供
--use-latest-restorable-time参数,则必须指定。 - 如果
--use-latest-restorable-time参数为true,则无法指定。 - 如果
--restore-type参数值为copy-on-write,则无法指定。 --source-db-cluster-identifier— 要从中还原的源集群的名称。该集群必须存在且可用。--use-latest-restorable-time或--no-use-latest-restorable-time— 是否还原至最近的可还原备份时间。如果未提供--restore-to-time参数,则无法指定。
AWS CLI 操作 restore-db-cluster-to-point-in-time 仅还原集群,而不还原该集群的实例。您必须调用 create-db-instance 操作为还原的集群创建实例,并在 --db-cluster-identifier 中指定还原的集群的标识符。 您只能在完成 restore-db-cluster-to-point-in-time 操作并且还原的集群可用 后创建实例。
以下示例从快照 sample-cluster-snapshot 创建到最近可还原时间的 sample-cluster-restored。
对于 Linux、macOS 或 Unix:
1. aws docdb restore-db-cluster-to-point-in-time \
2. --db-cluster-identifier sample-cluster-restored \
3. --source-db-cluster-identifier sample-cluster-snapshot \
4. --use-latest-restorable-time
对于 Windows:
1. aws docdb restore-db-cluster-to-point-in-time ^
2. --db-cluster-identifier sample-cluster-restored ^
3. --source-db-cluster-identifier sample-cluster-snapshot ^
4. --use-latest-restorable-time
以下示例从快照 sample-cluster-snapshot 创建到 2018 年 12 月 11 日 03:15 (UTC)(在 sample-cluster 的备份保留期内)的 sample-cluster-restored。
对于 Linux、macOS 或 Unix:
1. aws docdb restore-db-cluster-to-point-in-time \
2. --db-cluster-identifier sample-cluster-restore \
3. --source-db-cluster-identifier sample-cluster \
4. --restore-to-time 2020-05-12T03:15:00Z
对于 Windows:
1. aws docdb restore-db-cluster-to-point-in-time ^
2. --db-cluster-identifier sample-cluster-restore ^
3. --source-db-cluster-identifier sample-cluster ^
4. --restore-to-time 2020-05-12T03:15:00Z
此操作的输出将类似于下文。
1. {
2. "DBCluster": {
3. "AvailabilityZones": [
4. "us-east-1c",
5. "us-west-2b",
6. "us-west-2a"
7. ],
8. "BackupRetentionPeriod": 1,
9. "DBClusterIdentifier": "sample-cluster-restored",
10. "DBClusterParameterGroup": "sample-parameter-group",
11. "DBSubnetGroup": "default",
12. "Status": "creating",
13. "Endpoint": "sample-cluster-restored.node.us-east-1.docdb.amazonaws.com",
14. "ReaderEndpoint": "sample-cluster-restored.node.us-east-1.docdb.amazonaws.com",
15. "MultiAZ": false,
16. "Engine": "docdb",
17. "EngineVersion": "4.0.0",
18. "Port": 27017,
19. "MasterUsername": "master-user",
20. "PreferredBackupWindow": "02:00-02:30",
21. "PreferredMaintenanceWindow": "tue:09:50-tue:10:20",
22. "DBClusterMembers": [],
23. "VpcSecurityGroups": [
24. {
25. "VpcSecurityGroupId": "sg-abc0123",
26. "Status": "active"
27. }
28. ],
29. "HostedZoneId": "ABCDEFGHIJKLM",
30. "StorageEncrypted": true,
31. "KmsKeyId": "arn:aws:kms:us-east-1:<accountID^>:key/sample-key",
32. "DbClusterResourceId": "cluster-ABCDEFGHIJKLMNOPQRSTUVWXYZ",
33. "DBClusterArn": "arn:aws:rds:us-east-1:<accountID>:cluster:sample-cluster-restored",
34. "AssociatedRoles": [],
35. "ClusterCreateTime": "2020-04-24T20:14:36.713Z",
36. "DeletionProtection": false
37. }
38. }
