如何使用 AWS CLI 命令來管理快照並為 Lightsail 執行個體建立備份?
我想使用 AWS Command Line Interface (AWS CLI) 命令,來管理我的快照並為我的 Amazon Lightsail 執行個體建立備份。
解決方法
注意:
- 如果您在執行 AWS CLI 命令時收到錯誤,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
- JSON 是預設 AWS CLI 輸出。您可以使用預設值,或將 --output json 附加至命令來接收輸出,如下列範例所示。如需詳細資訊,請參閱從 AWS CLI 控制命令輸出。
- AWS CLI 輸出以 Unix Epoch 時間顯示時間戳記。使用第三方轉換器來轉換時間戳記,例如 epochconverter.com。
管理手動備份
使用 AWS CLI 命令來管理執行個體的手動備份,並列出可用的快照。
為 Lightsail 執行個體建立手動備份
執行 create-instance-snapshot 命令,以建立 Lightsail 執行個體的快照。下列範例在 eu-west-1 AWS 區域中建立執行個體 SnapshotTestLightsailInstance1 的快照:
# aws lightsail create-instance-snapshot --instance-name TestLightsailInstance1 --instance-snapshot-name SnapshotTestLightsailInstance1{ "operations": [ { "id": "d3196be7-3dc6-4508-b335-16ce45f11c90", "resourceName": "SnapshotTestLightsailInstance1", "resourceType": "InstanceSnapshot", "createdAt": 1602180831.638, "location": { "availabilityZone": "all", "regionName": "eu-west-1" }, "isTerminal": false, "operationDetails": "TestLightsailInstance1", "operationType": "CreateInstanceSnapshot", "status": "Started", "statusChangedAt": 1602180831.638 }, { "id": "df237a33-bca9-4fc3-8f46-ea5d12606f5c", "resourceName": "TestLightsailInstance1", "resourceType": "Instance", "createdAt": 1602180831.638, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": false, "operationDetails": "SnapshotTestLightsailInstance1", "operationType": "CreateInstanceSnapshot", "status": "Started", "statusChangedAt": 1602180831.638 } ] }
**注意:**將 instance-snapshot-name、instance-name 和 region 取代為您的值。
列出可用的快照
執行 get-instance-snapshots 命令,以列出 Lightsail 執行個體的所有快照。下列範例顯示 eu-west-1 區域中可用快照的詳細資訊:
# aws lightsail get-instance-snapshots --region eu-west-1 --query 'instanceSnapshots[].{name:name,createdAt:createdAt,resourceType:resourceType,state:state,fromInstanceName:fromInstanceName,sizeInGb:sizeInGb}' --output table ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | GetInstanceSnapshots | +----------------+-----------------------------------------+------------------------------------------------------------------------------------------------------------+-------------------+-----------+-------------+ | createdAt | fromInstanceName | name | resourceType | sizeInGb | state | +----------------+-----------------------------------------+------------------------------------------------------------------------------------------------------------+-------------------+-----------+-------------+ | 1602180831.638| TestLightsailInstance1 | SnapshotTestLightsailInstance1 | InstanceSnapshot | 40 | available | +----------------+-----------------------------------------+------------------------------------------------------------------------------------------------------------+-------------------+-----------+-------------+
**注意:**將 region 取代為您的區域。
管理自動備份
使用 AWS CLI 命令來驗證是否已為您的執行個體開啟自動快照,並開啟自動快照。您也可以列出自動快照,並透過具有更大套件大小或更高 Lightsail 計畫的備份建立新執行個體。
驗證是否已為您的執行個體開啟自動快照
執行下列命令,以驗證是否已為您的執行個體開啟自動快照並顯示定義的排程:
# aws lightsail get-instances --region eu-west-1 --query 'instances[].{addOns:addOns,name:name,publicIpAddress:publicIpAddress,AutoMatciSnapshotStatus:(addOns[].status),Schedule:(addOns[].snapshotTimeOfDay)}' --output text| grep -w "TestLightsailInstance1"['Enabled'] ['20:00'] [{'name': 'AutoSnapshot', 'status': 'Enabled', 'snapshotTimeOfDay': '20:00'}] TestLightsailInstance1 3.250.xx.xx
**注意:**將 TestLightsailInstance1 取代為您的執行個體名稱,並將 region 取代為您的區域。
開啟自動快照
執行 enable-add-on 命令,以為您的 Lightsail 執行個體開啟自動快照。下列範例建立每日自動快照,這些快照設定為以 UTC (08PM UTC) 為單位的每小時增量:
# aws lightsail enable-add-on --region eu-west-1 --resource-name TestLightsailInstance1 --add-on-request addOnType=AutoSnapshot,autoSnapshotAddOnRequest={snapshotTimeOfDay=20:00}{ "operations": [ { "id": "823bb162-9848-4897-b845-8f41c375801a", "resourceName": "TestLightsailInstance1", "resourceType": "Instance", "createdAt": 1602181856.652, "location": { "availabilityZone": "eu-west-1", "regionName": "eu-west-1" }, "isTerminal": false, "operationDetails": "EnableAddOn - AutoSnapshot", "operationType": "EnableAddOn", "status": "Started" } ] }
**注意:**將 resource-name、snapshotTimeOfDay 和 region 取代為您的值。
列出自動快照,並透過具有更大套件大小或更高 Lightsail 計畫的備份建立新執行個體
執行 get-auto-snapshots 命令,以列出 Lightsail 執行個體或磁碟的所有可用自動快照。下列範例顯示了執行個體 TestLightsailInstance1 的可用快照的詳細資訊:
# aws lightsail get-auto-snapshots --region eu-west-1 --resource-name TestLightsailInstance1{ "resourceName": "TestLightsailInstance1", "resourceType": "Instance", "autoSnapshots": [ { "date": "2020-10-08", "createdAt": 1602188663.0, "status": "Success", "fromAttachedDisks": [] } ] }
**注意:**將 resource-name 和 region 取代為您的值。
執行 create-instances-from-snapshot 命令,以從手動或自動備份建立 Lightsail 執行個體。下列範例使用特定備份和更大大小的套件,在 eu-west-1 區域中建立執行個體:
# aws lightsail create-instances-from-snapshot --region eu-west-1 --instance-snapshot-name SnapshotTestLightsailInstance1 --instance-names RestoredTestLightsailInstance1-New --availability-zone eu-west-1a --bundle-id large_2_0{ "operations": [ { "id": "09f7d1bb-90f4-48dc-b304-543499e11208", "resourceName": "RestoredTestLightsailInstance1-New", "resourceType": "Instance", "createdAt": 1602182374.625, "location": { "availabilityZone": "eu-west-1a", "regionName": "eu-west-1" }, "isTerminal": false, "operationType": "CreateInstancesFromSnapshot", "status": "Started", "statusChangedAt": 1602182374.625 } ] }
**注意:**將 instance-snapshot-name、instance-names、bundle-id 和 region 取代為您的值。
以下是您建立的 Lightsail 執行個體 RestoredTestLightsailInstance1-New 的詳細資訊範例:
# aws lightsail get-instances --region eu-west-1 --query 'instances[].{name:name,createdAt:createdAt,blueprintId:blueprintId,blueprintName:blueprintName,publicIpAddress:publicIpAddress}' --output table |grep -i RestoredTestLightsailInstance1-New | wordpress | WordPress | 1602182374.625 | RestoredTestLightsailInstance1-New | 34.247.xx.xx |
相關資訊
相關內容
- 已提問 10 個月前lg...
- 已提問 3 個月前lg...
- 已提問 1 年前lg...
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 3 年前
- AWS 官方已更新 1 年前