

# チュートリアル: AWS CLI を使用して DB クラスターのスナップショットから DB クラスターを復元する
<a name="tut-restore-cluster.CLI"></a>

このチュートリアルでは、AWS CLI を使用して DB クラスターのスナップショットから DB クラスターを復元します。AWS CLI を使用してスナップショットから DB クラスターを復元するには、次の 2 つのステップを実行します。

1. [restore-db-cluster-from-snapshot](https://docs.aws.amazon.com/cli/latest/reference/rds/restore-db-cluster-from-snapshot.html) コマンドを使用した [DB クラスターの復元](#tut-restore-cluster.CLI.restore)

1. [create-db-instance](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html) コマンドを使用した [プライマリ (ライター) DB インスタンスの作成](#tut-restore-cluster.CLI.create)

## DB クラスターの復元
<a name="tut-restore-cluster.CLI.restore"></a>

`restore-db-cluster-from-snapshot` コマンドを使用します。以下のオプションは必須です。
+ `--db-cluster-identifier` - 復元された DB クラスターの名前。
+ `--snapshot-identifier` - 復元の元となるスナップショットの名前。
+ `--engine` - 復元された DB クラスターのデータベースエンジン。復元するクラスターは、ソース DB クラスターのデータベースエンジンと互換性がある必要があります。

  選択肢は次のとおりです。
  + `aurora-mysql` – Aurora MySQL 5.7 および 8.0 互換。
  + `aurora-postgresql` – Aurora PostgreSQL 互換。

  この例では、`aurora-mysql` を使用します。
+ `--engine-version` - 復元された DB クラスターのバージョン。この例では、MySQL-8.0 と互換性があるバージョンを使用します。

次の例では、`my-57-cluster-snapshot` という名前の DB クラスターのスナップショットから `my-new-80-cluster` という名前のAurora MySQL 8.0 と互換性がある DB クラスターを復元します。

**DB クラスターを復元するには**
+ 以下のいずれかのコマンドを使用します。

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

## プライマリ (ライター) DB インスタンスの作成
<a name="tut-restore-cluster.CLI.create"></a>

プライマリ (ライター) DB インスタンスを作成するには、`create-db-instance` コマンドを使用します。以下のオプションは必須です。
+ `--db-cluster-identifier` - 復元された DB クラスターの名前。
+ `--db-instance-identifier` - プライマリ DB インスタンスの名前。
+ `--db-instance-class` - プライマリ DB インスタンスのインスタンスクラス。この例では、`db.t3.medium` を使用します。
**注記**  
T DB インスタンスクラスは、開発およびテストサーバー、またはその他の本稼働以外のサーバーにのみ使用することをお勧めします。T インスタンスクラスの詳細については、「[DB インスタンスクラスタイプ](Concepts.DBInstanceClass.Types.md)」を参照してください。
+ `--engine`— プライマリ DB インスタンスのデータベースエンジン。データベースエンジンは、復元された DB クラスターが使用するエンジンと同じである必要があります。

  選択肢は次のとおりです。
  + `aurora-mysql` – Aurora MySQL 5.7 および 8.0 互換。
  + `aurora-postgresql` – Aurora PostgreSQL 互換。

  この例では、`aurora-mysql` を使用します。

次の例では、`my-new-80-cluster` という名前の復元された Aurora MySQL 8.0 互換 DB クラスターで `my-new-80-cluster-instance` という名前のプライマリ (ライター) DB インスタンスを作成します。

**プライマリ DB インスタンスを作成するには**
+ 以下のいずれかのコマンドを使用します。

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