教學:從資料庫叢集快照還原 Amazon Aurora 資料庫叢集 - Amazon Aurora

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

教學:從資料庫叢集快照還原 Amazon Aurora 資料庫叢集

使用 Amazon Aurora 的一個常見情況是,您有一個偶爾使用的資料庫執行個體,但該執行個體不需全時段可用。例如,您可能使用資料庫叢集來保留每個季度執行的報表資料。在此情況下,節省支出的方式就是在報告完成後建立資料庫叢集的資料庫叢集快照。然後,您便可以刪除資料庫叢集,並在下個季度需要上傳新資料並執行報表時將其還原。

還原資料庫叢集時,您需要提供要還原之資料庫叢集快照的名稱。然後,您需提供從還原作業中建立的新資料庫叢集名稱。如需有關從快照還原資料庫叢集的詳細資訊,請參閱 從資料庫叢集快照還原

在本教學課程中,我們也將 Aurora MySQL 版本 2 (與 MySQL 5.7 相容) 資料庫叢集升級還原至 Aurora MySQL 版本 3 (與 MySQL 8.0 相容) 的資料庫叢集。

使用 Amazon RDS 主控台,從資料庫叢集快照還原資料庫叢集

使用 AWS Management Console 從快照還原資料庫叢集時,也會建立主要 (寫入器) 資料庫執行個體。

注意

建立主要資料庫執行個體時,會顯示為讀取器執行個體,但是,完成建立之後便是寫入器執行個體。

從資料庫叢集快照還原資料庫叢集
  1. 登入 AWS Management Console,開啟位於 https://console.aws.amazon.com/rds/ 的 Amazon RDS 主控台。

  2. 在導覽窗格中,選擇 Snapshots (快照)。

  3. 選擇想要從中還原的資料庫叢集快照。

  4. 針對 Actions (動作),選擇 Restore snapshot (還原快照)。

    RDS 主控台中 Actions (動作) 選單中的還原快照選項

    Restore snapshot (還原快照) 頁面隨即出現。

  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) (虛擬私有雲端 (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. 選擇 Restore DB instance (還原資料庫執行個體)。

Databases (資料庫) 頁面會顯示還原的資料庫叢集,其狀態為 Creating

資料庫頁面上的還原資料庫叢集

建立主要資料庫執行個體時,會顯示為讀取器執行個體,但是,完成建立之後便是寫入器執行個體。

使用 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 相容的資料庫叢集。

還原資料庫叢集
  • 請使用下列其中一個命令。

    對於LinuxmacOS、或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.

以下範例會在名為 my-new-80-cluster 的已還原的 Aurora MySQL 8.0 相容資料庫叢集中,建立名為 my-new-80-cluster-instance 的主要 (寫入器) 資料庫執行個體。

建立主要資料庫執行個體
  • 請使用下列其中一個命令。

    對於LinuxmacOS、或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": [] } }