教程:从数据库集群快照中还原 Amazon Aurora 数据库集群 - Amazon Aurora
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

教程:从数据库集群快照中还原 Amazon Aurora 数据库集群

使用 Amazon Aurora 的一个常见情况就是您有一个偶尔使用而不是一直使用的数据库实例。例如,您可以使用数据库集群来保存仅每季度运行一次的报告的数据。在这种情况下节省资金的一种方法是在完成报告后创建数据库集群的数据库集群快照。然后,您删除数据库集群,并在需要上载新数据以及在下一季度运行报告时将其还原。

在还原数据库集群时,您需要提供用来还原的数据库集群快照的名称。然后,为通过还原操作创建的新数据库集群提供名称。有关从快照还原数据库集群的更多详细信息,请参阅从数据库集群快照还原

在本教程中,我们还将还原的数据库集群从 Aurora MySQL 版本 2(与 MySQL 5.7 兼容)升级到 Aurora MySQL 版本 3(与 MySQL 8.0 兼容)。

使用 Amazon RDS 控制台从数据库集群快照中还原数据库集群

使用 Amazon Web Services Management Console从快照还原数据库集群时,还将创建主(写入器)数据库实例。

注意

在创建主数据库实例时,它显示为读取器实例,但创建后,它是写入器实例。

从数据库集群快照还原数据库集群
  1. 登录Amazon Web Services Management Console并通过以下网址打开 Amazon RDS 控制台:https://console.aws.amazon.com/rds/

  2. 在导航窗格中,选择快照

  3. 选择要从其还原的数据库集群快照。

  4. 对于操作,选择还原快照

    
                        RDS 控制台操作菜单中的还原快照选项

    此时会显示还原快照页面。

  5. DB instance settings(数据库实例设置)下,执行下列操作:

    1. DB engine(数据库引擎)使用原定设置。

    2. 对于 Available versions(可用版本),选择与 MySQL 8.0 兼容的版本,例如 Aurora MySQL 3.02.0 (compatible with MySQL 8.0.23) [Aurora MySQL 3.02.0(与 MySQL 8.0.23 兼容)]。

    
                        还原快照页面
  6. Settings(设置)下的 DB cluster identifier(数据库集群标识符)中,输入要用于还原的数据库集群的唯一名称,如 my-80-cluster

  7. Connectivity(连接)项下,使用以下各项的默认设置:

    • Virtual Private Cloud (VPC)

    • DB subnet group(数据库子网组)

    • 公有访问权限

    • VPC security group (firewall) [VPC 安全组(防火墙)]

  8. 选择 DB instance class(数据库实例类)。

    在本教程中,请选择 Burstable classes (includes t classes) [突增型类(包括 t 类)],然后选择 db.t3.medium

    注意

    建议仅将 T 数据库实例类用于开发和测试服务器,或其他非生产服务器。有关 T 实例类的更多详细信息,请参阅数据库实例类类型

    
                        实例配置
  9. 对于 Database authentication(数据库身份验证),请使用原定设置。

  10. 使用 Encryption(加密)项的默认设置。

    如果快照的源数据库集群已加密,则还原的数据库集群也会加密。您无法将其设置为未加密。

  11. 展开页面底部的 Additional configuration(其他配置)。

    
                        其他配置
  12. 进行以下选择:

    1. 对于本教程,为 DB cluster parameter group(数据库集群参数组)使用原定设置值。

    2. 对于本教程,为 DB parameter group(数据库参数组)使用原定设置值。

    3. 对于 Log exports(日志导出),选中所有复选框。

    4. 对于 Deletion protection(删除保护),选中 Enable deletion protection(启用删除保护)复选框。

  13. 选择还原数据库实例

Databases(数据库)页面会显示状态为 Creating 的已还原数据库集群。


                Databases(数据库)页面上已还原的数据库集群

在创建主数据库实例时,它显示为读取器实例,但创建后,它是写入器实例。

使用 Amazon CLI 从数据库集群快照中还原数据库集群

使用 Amazon CLI 从快照还原恢复数据库集群有两个步骤:

还原数据库集群

您使用 restore-db-cluster-from-snapshot 命令。以下选项为必填:

  • --db-cluster-identifier – 已还原的数据库集群的名称。

  • --snapshot-identifier – 要从中进行还原的数据库快照的名称。

  • --engine – 已还原的数据库集群的数据库引擎。它必须与源数据库集群的数据库引擎兼容。

    选项如下:

    • aurora-mysql – 与 Aurora MySQL 5.7 和 8.0 兼容。

    • aurora-postgresql – 与 Aurora PostgreSQL 兼容。

    在此示例中,我们使用的是 aurora-mysql

  • --engine-version – 已还原的数据库集群的版本。在此示例中,我们使用与 MySQL 8.0 兼容的版本。

以下示例从名为 my-57-cluster-snapshot 的数据库集群快照中还原与 Aurora MySQL 8.0 兼容的名为 my-new-80-cluster 的数据库集群。

还原数据库集群
  • 使用以下命令之一。

    对于 Linux、macOS 或 Unix:

    aws rds restore-db-cluster-from-snapshot \ --db-cluster-identifier my-new-80-cluster \ --snapshot-identifier my-57-cluster-snapshot \ --engine aurora-mysql \ --engine-version 8.0.mysql_aurora.3.02.0

    对于 Windows:

    aws rds restore-db-cluster-from-snapshot ^ --db-cluster-identifier my-new-80-cluster ^ --snapshot-identifier my-57-cluster-snapshot ^ --engine aurora-mysql ^ --engine-version 8.0.mysql_aurora.3.02.0

输出与以下内容类似。

{ "DBCluster": { "AllocatedStorage": 1, "AvailabilityZones": [ "eu-central-1b", "eu-central-1c", "eu-central-1a" ], "BackupRetentionPeriod": 14, "DatabaseName": "", "DBClusterIdentifier": "my-new-80-cluster", "DBClusterParameterGroup": "default.aurora-mysql8.0", "DBSubnetGroup": "default", "Status": "creating", "Endpoint": "my-new-80-cluster.cluster-############.eu-central-1.rds.amazonaws.com", "ReaderEndpoint": "my-new-80-cluster.cluster-ro-############.eu-central-1.rds.amazonaws.com", "MultiAZ": false, "Engine": "aurora-mysql", "EngineVersion": "8.0.mysql_aurora.3.02.0", "Port": 3306, "MasterUsername": "admin", "PreferredBackupWindow": "01:55-02:25", "PreferredMaintenanceWindow": "thu:21:14-thu:21:44", "ReadReplicaIdentifiers": [], "DBClusterMembers": [], "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-########", "Status": "active" } ], "HostedZoneId": "Z1RLNU0EXAMPLE", "StorageEncrypted": true, "KmsKeyId": "arn:aws:kms:eu-central-1:123456789012:key/#######-5ccc-49cc-8aaa-############", "DbClusterResourceId": "cluster-ZZ12345678ITSJUSTANEXAMPLE", "DBClusterArn": "arn:aws:rds:eu-central-1:123456789012:cluster:my-new-80-cluster", "AssociatedRoles": [], "IAMDatabaseAuthenticationEnabled": false, "ClusterCreateTime": "2022-07-05T20:45:42.171000+00:00", "EngineMode": "provisioned", "DeletionProtection": false, "HttpEndpointEnabled": false, "CopyTagsToSnapshot": false, "CrossAccountClone": false, "DomainMemberships": [], "TagList": [] } }

创建主(写入器)数据库实例

要创建主(写入器)数据库实例,请使用 create-db-instance 命令。以下选项为必填:

  • --db-cluster-identifier – 已还原的数据库集群的名称。

  • --db-instance-identifier – 主数据库实例的名称。

  • --db-instance-class – 主数据库实例类的实例名称。在此示例中,我们使用的是 db.t3.medium

    注意

    建议仅将 T 数据库实例类用于开发和测试服务器,或其他非生产服务器。有关 T 实例类的更多详细信息,请参阅数据库实例类类型

  • --engine –主数据库实例的数据库引擎。它必须与已还原的数据库集群使用的数据库引擎相同。

    选项如下:

    • aurora-mysql – 与 Aurora MySQL 5.7 和 8.0 兼容。

    • aurora-postgresql – 与 Aurora PostgreSQL 兼容。

    在此示例中,我们使用的是 aurora-mysql

以下示例在已还原的与 Aurora MySQL 8.0 兼容且名为 my-new-80-cluster 的数据库集群中创建一个名为 my-new-80-cluster-instance 的主(写入器)数据库实例。

创建主数据库实例
  • 使用以下命令之一。

    对于 Linux、macOS 或 Unix:

    aws rds create-db-instance \ --db-cluster-identifier my-new-80-cluster \ --db-instance-identifier my-new-80-cluster-instance \ --db-instance-class db.t3.medium \ --engine aurora-mysql

    对于 Windows:

    aws rds create-db-instance ^ --db-cluster-identifier my-new-80-cluster ^ --db-instance-identifier my-new-80-cluster-instance ^ --db-instance-class db.t3.medium ^ --engine aurora-mysql

输出与以下内容类似。

{ "DBInstance": { "DBInstanceIdentifier": "my-new-80-cluster-instance", "DBInstanceClass": "db.t3.medium", "Engine": "aurora-mysql", "DBInstanceStatus": "creating", "MasterUsername": "admin", "AllocatedStorage": 1, "PreferredBackupWindow": "01:55-02:25", "BackupRetentionPeriod": 14, "DBSecurityGroups": [], "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-########", "Status": "active" } ], "DBParameterGroups": [ { "DBParameterGroupName": "default.aurora-mysql8.0", "ParameterApplyStatus": "in-sync" } ], "DBSubnetGroup": { "DBSubnetGroupName": "default", "DBSubnetGroupDescription": "default", "VpcId": "vpc-2305ca49", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-########", "SubnetAvailabilityZone": { "Name": "eu-central-1a" }, "SubnetOutpost": {}, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-########", "SubnetAvailabilityZone": { "Name": "eu-central-1b" }, "SubnetOutpost": {}, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-########", "SubnetAvailabilityZone": { "Name": "eu-central-1c" }, "SubnetOutpost": {}, "SubnetStatus": "Active" } ] }, "PreferredMaintenanceWindow": "sat:02:41-sat:03:11", "PendingModifiedValues": {}, "MultiAZ": false, "EngineVersion": "8.0.mysql_aurora.3.02.0", "AutoMinorVersionUpgrade": true, "ReadReplicaDBInstanceIdentifiers": [], "LicenseModel": "general-public-license", "OptionGroupMemberships": [ { "OptionGroupName": "default:aurora-mysql-8-0", "Status": "in-sync" } ], "PubliclyAccessible": false, "StorageType": "aurora", "DbInstancePort": 0, "DBClusterIdentifier": "my-new-80-cluster", "StorageEncrypted": true, "KmsKeyId": "arn:aws:kms:eu-central-1:534026745191:key/#######-5ccc-49cc-8aaa-############", "DbiResourceId": "db-5C6UT5PU0YETANOTHEREXAMPLE", "CACertificateIdentifier": "rds-ca-2019", "DomainMemberships": [], "CopyTagsToSnapshot": false, "MonitoringInterval": 0, "PromotionTier": 1, "DBInstanceArn": "arn:aws:rds:eu-central-1:123456789012:db:my-new-80-cluster-instance", "IAMDatabaseAuthenticationEnabled": false, "PerformanceInsightsEnabled": false, "DeletionProtection": false, "AssociatedRoles": [], "TagList": [] } }