Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
AWS CLI コマンドを使用してスナップショットを管理したり、Lightsail インスタンスのバックアップを作成したりするにはどうすればよいですか?
AWS コマンドラインインターフェイス (AWS CLI) のコマンドを使用してスナップショットを管理したり、Amazon Lightsail インスタンスのバックアップを作成したりすることを考えています。
解決策
注:
- AWS CLI のコマンドの実行時にエラーが発生する場合は、「AWS CLI エラーのトラブルシューティング」を参照してください。また、AWS CLI の最新バージョンを使用していることを確認してください。
- JSON はデフォルトの AWS CLI 出力です。デフォルトを使用するか、コマンドに --output json を追加して、次の例のような出力を受け取ることができます。詳細については、「AWS CLI からのコマンド出力を制御する」を参照してください。
- AWS CLI の出力には、Unix エポック時間のタイムスタンプが表示されます。タイムスタンプを変換するには、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 (UTC 午後8時) で 1 時間単位の増分に設定された自動スナップショットを毎日作成します。
# 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 |
関連情報
AWS CLI Command Reference for Lightsail
