本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
教學課程:使用 AWS CLI 從資料庫叢集快照還原資料庫叢集
在本教學課程中,您會使用 AWS CLI 從資料庫叢集快照還原資料庫叢集。使用 AWS 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 的資料庫叢集快照,還原名為 my-new-80-cluster 與 Aurora MySQL 8.0 相容的資料庫叢集。
還原資料庫叢集
-
請使用下列其中一個命令。
對於 Linux、macOS 或 Unix:
aws rds restore-db-cluster-from-snapshot \ --db-cluster-identifiermy-new-80-cluster\ --snapshot-identifiermy-57-cluster-snapshot\ --engine aurora-mysql \ --engine-version8.0.mysql_aurora.3.02.0在 Windows 中:
aws rds restore-db-cluster-from-snapshot ^ --db-cluster-identifiermy-new-80-cluster^ --snapshot-identifiermy-57-cluster-snapshot^ --engine aurora-mysql ^ --engine-version8.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. -
以下範例會在名為 my-new-80-cluster 的已還原的 Aurora MySQL 8.0 相容資料庫叢集中,建立名為 my-new-80-cluster-instance 的主要 (寫入器) 資料庫執行個體。
建立主要資料庫執行個體
-
請使用下列其中一個命令。
對於 Linux、macOS 或 Unix:
aws rds create-db-instance \ --db-cluster-identifier my-new-80-cluster \ --db-instance-identifiermy-new-80-cluster-instance\ --db-instance-classdb.t3.medium\ --engine aurora-mysql在 Windows 中:
aws rds create-db-instance ^ --db-cluster-identifier my-new-80-cluster ^ --db-instance-identifiermy-new-80-cluster-instance^ --db-instance-classdb.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": [] } }