

# 教程：从数据库集群快照中还原 Amazon Aurora 数据库集群
<a name="tut-restore-cluster"></a>

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

在还原数据库集群时，您需要提供用来还原的数据库集群快照的名称。然后，为通过还原操作创建的新数据库集群提供名称。有关从快照还原数据库集群的更多详细信息，请参阅[从数据库集群快照还原](aurora-restore-snapshot.md)。

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

使用 Amazon RDS 控制台或 AWS CLI，通过数据库集群快照将数据库集群还原到指定时间。

有关 Amazon RDS 的 AWS KMS 密钥管理的信息，请参阅 [AWS KMS key 管理](Overview.Encryption.Keys.md)。

**Topics**
+ [

# 教程：使用 Amazon RDS 控制台从数据库集群快照中还原数据库集群
](tut-restore-cluster.console.md)
+ [

# 教程：使用 AWS CLI 从数据库集群快照中还原数据库集群
](tut-restore-cluster.CLI.md)

# 教程：使用 Amazon RDS 控制台从数据库集群快照中还原数据库集群
<a name="tut-restore-cluster.console"></a>

在本教程中，您使用 Amazon RDS 控制台从数据库集群快照中还原数据库集群。使用 AWS 管理控制台从快照还原数据库集群时，还将创建主（写入器）数据库实例。

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

**从数据库集群快照还原数据库集群**

1. 登录 AWS 管理控制台 并通过以下网址打开 Amazon RDS 控制台：[https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)。

1. 在导航窗格中，选择**快照**。

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

1. 对于**操作**，选择**还原快照**。  
![\[RDS 控制台操作菜单中的还原快照选项\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/tut-restore-cluster1.png)

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

1. 在 **DB instance settings**（数据库实例设置）下，执行下列操作：

   1. 对 **DB engine**（数据库引擎）使用默认设置。

   1. 对于**可用版本**，选择与 MySQL 8.0 兼容的版本，例如 **Aurora MySQL 3.04.0（与 MySQL 8.0.28 兼容）**。  
![\[还原快照页面\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/tut-restore-cluster2.png)

1. 在 **Settings**（设置）项下的 **DB instance identifier**（数据库实例标识符）中，输入要用于还原的数据库实例的唯一名称，如 **my-80**。
**注意**  
为创建数据库集群标识符，Amazon RDS 将 `-cluster` 附加到您指定的数据库实例标识符之后。

1. 在 **Connectivity**（连接）项下，使用以下各项的默认设置：
   + **Virtual Private Cloud (VPC)** [虚拟私有云（VPC）]
   + **DB subnet group**（数据库子网组）
   + **公有访问权限**
   + **VPC security group (firewall)** [VPC 安全组（防火墙）]

1. 选择 **DB instance class**（数据库实例类）。

   在本教程中，请选择 **Burstable classes (includes t classes)** [突增型类（包括 t 类）]，然后选择 **db.t3.medium**。
**注意**  
建议仅将 T 数据库实例类用于开发和测试服务器，或其他非生产服务器。有关 T 实例类的更多详细信息，请参阅[数据库实例类类型](Concepts.DBInstanceClass.Types.md)。  
![\[数据库实例配置面板，其中包含还原期间的实例类、可用性和性能设置选项。\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/tut-restore-cluster3.png)

1. 对于 **Database authentication**（数据库身份验证），请使用默认设置。

1. 使用 **Encryption**（加密）项的默认设置。

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

1. 展开页面底部的 **Additional configuration**（其他配置）。  
![\[用于数据库还原的其它配置选项，包括网络设置、加密和维护首选项。\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/tut-restore-cluster4.png)

1. 进行以下选择：

   1. 对于本教程，为 **DB cluster parameter group**（数据库集群参数组）使用默认值。

   1. 对于本教程，为 **DB parameter group**（数据库参数组）使用默认值。

   1. 对于 **Log exports**（日志导出），选中所有复选框。

   1. 对于 **Deletion protection**（删除保护），选中 **Enable deletion protection**（启用删除保护）复选框。

1. 选择**还原数据库实例**。

**Databases**（数据库）页面会显示状态为 `Creating` 的已还原数据库集群。

![\[Databases（数据库）页面上已还原的数据库集群\]](http://docs.aws.amazon.com/zh_cn/AmazonRDS/latest/AuroraUserGuide/images/tut-restore-cluster5.png)


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

# 教程：使用 AWS CLI 从数据库集群快照中还原数据库集群
<a name="tut-restore-cluster.CLI"></a>

在本教程中，您使用 AWS CLI 从数据库集群快照中还原数据库集群。使用 AWS CLI 从快照还原恢复数据库集群有两个步骤：

1. [还原数据库集群](#tut-restore-cluster.CLI.restore) 使用 [restore-db-cluster-from-snapshot](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-cluster-from-snapshot.html) 命令

1. [创建主（写入器）数据库实例](#tut-restore-cluster.CLI.create) 使用 [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) 命令

## 还原数据库集群
<a name="tut-restore-cluster.CLI.restore"></a>

您使用 `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": []
    }
}
```

## 创建主（写入器）数据库实例
<a name="tut-restore-cluster.CLI.create"></a>

要创建主（写入器）数据库实例，请使用 `create-db-instance` 命令。以下选项为必填：
+ `--db-cluster-identifier` – 已还原的数据库集群的名称。
+ `--db-instance-identifier` – 主数据库实例的名称。
+ `--db-instance-class` – 主数据库实例类的实例名称。在此示例中，我们使用的是 `db.t3.medium`。
**注意**  
建议仅将 T 数据库实例类用于开发和测试服务器，或其他非生产服务器。有关 T 实例类的更多详细信息，请参阅[数据库实例类类型](Concepts.DBInstanceClass.Types.md)。
+ `--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": []
    }
}
```