2016-12-08 58 views
2

通過控制檯很容易,但我需要從CLI執行相同的操作。AWS Aurora:如何通過aws cli恢復數據庫集羣快照?

首先,我創建了一個數據庫快照:

aws rds create-db-cluster-snapshot \ 
    --db-cluster-snapshot-identifier $SNAPSHOT_ID \ 
    --db-cluster-identifier $CLUSTER \ 

羣只有一個作家實例

,因爲它throwned錯誤

客戶端的錯誤,我沒有使用create-db-snapshot方法(InvalidParameterValue )在調用CreateDBSnapshot操作時發生:指定的實例是羣集的成員,並且不能直接創建快照。請改用CreateDBClusterSnapshot API。

它的工作原理:

aws rds create-db-cluster-snapshot \ 
    --db-cluster-snapshot-identifier $SNAPSHOT_ID \ 
    --db-cluster-identifier $CLUSTER \ 
{ 
    "DBClusterSnapshot": { 
     "Engine": "aurora", 
     "SnapshotCreateTime": "2016-12-08T11:48:07.534Z", 
    .... 
} 

所以,我想從快照還原一個新極光集羣,然後我想:

aws rds restore-db-instance-from-db-snapshot \ 
    --db-instance-identifier from-snap2 \ 
    --db-snapshot-identifier snap2 \ 

A client error (DBSnapshotNotFound) occurred when calling the RestoreDBInstanceFromDBSnapshot operation: DBSnapshot not found: snap2 

所以,我試圖與恢復:

aws rds restore-db-cluster-from-snapshot \ 
    --db-cluster-identifier from-snap2 \ 
    --snapshot-identifier snap2 \ 
    --engine aurora \ 
    --vpc-security-group-ids $PREPROD_SG \ 
    --db-subnet-group-name my-db-subnet-group \ 

它的工作原理...

{ 
    "DBCluster": { 
     ... 
     "EngineVersion": "5.6.10a", 
     "DBClusterIdentifier": "from-snap2", 
... 
     "DBClusterMembers": [], 
... 
} 

但爲什麼集羣不包含任何Aurora實例?

錯誤在哪裏?

回答

2

這非常不直觀。如果從快照還原集羣,但集羣中沒有成員實例,那麼實際上哪些操作成功了?看起來好像所有這些都是創建某種邏輯實體,也許是後備存儲,但沒有實例。

奇怪。但是,API documentation確實在示例響應中顯示集羣成員爲空集。

<DBClusterMembers/> 

因此,看來你創建一個集羣,像你一樣,那麼你顯然在集羣中創建實例,如在AWS論壇發帖解釋:

aws rds create-db-instance --db-instance-identifier my-instance --db-instance-class db.r3.large --engine aurora --db-subnet-group-name default-vpc-xxxxxx --db-cluster-identifier my-instance-cluster

https://forums.aws.amazon.com/thread.jspa?messageID=688727

顯然,控制檯在同一個動作後面封裝了多個API請求。從AWS支持

0

如果使用aws rds create-db-cluster-snapshot創建,則無法使用aws rds restore-db-instance-from-db-snapshot進行恢復。第一個創建數據庫快照,第二個恢復集羣快照,不同類型。

從你的問題看來你的恢復是正確的,也許你需要指定--database-name。您也可以嘗試使用僅需要的參數進行恢復,即不使用vpc sg或DB子網。

1

響應:

使用API​​調用和我們的工程師正在做這個工作時,這是一個已知的問題。即使羣集在通過CLI創建之後在AWS控制檯中可見,也不會在您的Aurora羣集中自動創建任何實例。在這種情況下,您需要創建一個數據庫實例並將其關聯到最近恢復的羣集。在AWS控制檯上執行此操作時,會爲羣集自動創建一個新實例,但來自CLI的操作使用獨立的API調用。

以下文檔提供了有關如何創建一個數據庫實例的詳細信息: http://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html

您可以描述使用AWS控制檯或使用CLI您的集羣: http://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-clusters.html

這裏是一個命令行示例創建實例並將其與虛構羣集相關聯: aws rds create-db-instance --engine aurora --db-cluster-identifier yourauroraclusteridentifier --db-instance-class db.t2.medium --db-instance-標識您的身份標識

就我而言,--db-cluster-identifier是從集羣快照創建的集羣。