Wie verwende ich AWS CLI-Befehle, um meine Snapshots zu verwalten und Backups für meine Lightsail-Instances zu erstellen?

Lesedauer: 4 Minute
0

Ich möchte die Befehle der AWS-Befehlszeilenschnittstelle (AWS CLI) verwenden, um meine Snapshots zu verwalten und Sicherungen für meine Amazon Lightsail-Instances zu erstellen.

Behebung

Hinweis:

Manuelle Sicherungen verwalten

Verwenden Sie AWS-CLI-Befehle, um manuelle Backups für Ihre Instance zu verwalten und verfügbare Snapshots aufzulisten.

Erstellen Sie ein manuelles Backup für eine Lightsail-Instance

Führen Sie den Befehl create-instance-snapshot aus, um einen Snapshot der Lightsail-Instance zu erstellen. Das folgende Beispiel erstellt einen Snapshot der Instance snapshotTestLightSailInstance1 in der AWS-Region eu-west-1:

# 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
        }
    ]
}

**Hinweis:**Ersetzen Sie instance-snapshot-name, instance-name und region durch Ihre Werte.

Listen Sie die verfügbaren Snapshots auf

Führen Sie den Befehl get-instance-snapshots aus, um alle Snapshots für Ihre Lightsail-Instances aufzulisten. Das folgende Beispiel zeigt Details der verfügbaren Snapshots in der Region 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  |
+----------------+-----------------------------------------+------------------------------------------------------------------------------------------------------------+-------------------+-----------+-------------+

**Hinweis:**Ersetzen Sie Region durch Ihre Region.

Automatische Sicherungen verwalten

Verwenden Sie AWS CLI-Befehle, um zu überprüfen, ob automatische Snapshots für Ihre Instances aktiviert sind, und aktivieren Sie automatische Snapshots. Sie können auch automatische Snapshots auflisten und eine neue Instance aus einer Sicherung mit einer höheren Bundle-Größe oder einem höheren Lightsail-Plan erstellen.

**Überprüfen Sie, ob automatische Snapshots für Ihre Instances aktiviert sind **

Führen Sie den folgenden Befehl aus, um zu überprüfen, ob automatische Snapshots für Ihre Instance aktiviert sind, und um den definierten Zeitplan anzuzeigen:

# 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

**Hinweis:**Ersetzen Sie TestLightSailInstance1 durch Ihren Instance-Namen und Region durch Ihre Region.

Aktivieren Sie automatische Snapshots

Führen Sie den Befehl enable-add-on aus, um automatische Snapshots für Ihre Lightsail-Instances zu aktivieren. Das folgende Beispiel erstellt tägliche automatische Snapshots, die auf ein stündliches Inkrement in UTC (08:00 Uhr UTC) eingestellt sind:

# 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"
        }
    ]
}

**Hinweis:**Ersetzen Sie resource-name, snapshotTimeOfDay und region durch Ihre Werte.

Listen Sie automatische Snapshots auf und erstellen Sie eine neue Instance aus der Sicherung mit einer höheren Bundle-Größe oder einem höheren Lightsail-Plan

Führen Sie den Befehl get-auto-snapshots aus, um alle verfügbaren automatischen Snapshots für Ihre Lightsail-Instances oder Festplatte aufzulisten. Das folgende Beispiel zeigt Details der verfügbaren Snapshots für die Instance 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": []
        }
    ]
}

**Hinweis:**Ersetzen Sie Resource-Name und Region durch Ihre Werte.

Führen Sie den Befehl create-instances-from-snapshot aus, um Lightsail-Instances aus einer manuellen oder automatischen Sicherung zu erstellen. Das folgende Beispiel verwendet eine bestimmte Sicherung und ein Paket mit höherer Größe, um eine Instance in der Region eu-west-1 zu erstellen:

# 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
        }
    ]
}

**Hinweis:**Ersetzen Sie instance-snapshot-name, instance-names, bundle-id und region durch Ihre Werte.

Im Folgenden finden Sie ein Beispiel für die Details der Lightsail-Instance RestoredTestLightSailInstance1-New, die Sie erstellt haben:

# 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    |

Ähnliche Informationen

AWS CLI-Befehlsreferenz für Lightsail

Lightsail API-Referenz

Wie kann ich mit AWS-CLI-Befehlen meine Lightsail-Instance verwalten?

Lightsail-Dokumente

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 2 Monaten