> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Snapshots verwalten

> In diesem Abschnitt lernst du, wie du Snapshots für deine Anwendungen und Datenbanken mit dem Python-SDK erstellst, abrufst und wiederherstellst.

[Client]: client

[Application]: client#application

Snapshots sind Backups deiner Anwendung oder Datenbank zu einem bestimmten Zeitpunkt. Sie ermöglichen es dir, deine Anwendung oder Datenbank bei Bedarf in einen früheren Zustand zurückzuversetzen. Square Cloud bietet unbegrenzte Snapshots mit automatischen täglichen Backups.

## Einen Anwendungs-Snapshot erstellen

`client.snapshot` gibt ein `Snapshot`-Objekt zurück.

<Tabs>
  <Tab title="Mit Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API_KEY')

    async def example():
        snapshot = await client.snapshot(app_id='application_id')
        
        print(snapshot.url)  # Download URL for the snapshot
        print(snapshot.key)  # Snapshot key identifier
    ```
  </Tab>

  <Tab title="Mit Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API_KEY')

    async def example():
        app = await client.app('application_id')
        snapshot = await app.snapshot()
        
        print(snapshot.url)  # Download URL for the snapshot
        print(snapshot.key)  # Snapshot key identifier
    ```
  </Tab>
</Tabs>

## Einen Snapshot herunterladen

Das `Snapshot`-Objekt stellt eine Methode bereit, um den Snapshot als ZIP-Datei herunterzuladen.

```python theme={null}
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    snapshot = await client.snapshot(app_id='application_id')
    
    # Download snapshot to current directory
    zip_file = await snapshot.download()
    
    # Download snapshot to specific directory
    zip_file = await snapshot.download(path='./backups')
```

## Anwendungs-Snapshots auflisten

`client.all_app_snapshots` gibt eine Liste von `SnapshotInfo`-Objekten zurück.

<Tabs>
  <Tab title="Mit Client">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API_KEY')

    async def example():
        snapshots = await client.all_app_snapshots(app_id='application_id')
        
        for snapshot in snapshots:
            print(f"Snapshot ID: {snapshot.id}")
            print(f"  Size: {snapshot.size}")
            print(f"  Created at: {snapshot.created_at}")
    ```
  </Tab>

  <Tab title="Mit Application">
    ```python theme={null}
    import squarecloud as square

    client = square.Client(api_key='API_KEY')

    async def example():
        app = await client.app('application_id')
        snapshots = await app.all_snapshots()
        
        for snapshot in snapshots:
            print(f"Snapshot ID: {snapshot.id}")
            print(f"  Size: {snapshot.size}")
            print(f"  Created at: {snapshot.created_at}")
    ```
  </Tab>
</Tabs>

## Einen Snapshot wiederherstellen

`client.restore_snapshot` gibt ein `Response`-Objekt zurück. Du kannst Snapshots sowohl für Anwendungen als auch für Datenbanken wiederherstellen.

```python theme={null}
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    # Restore an application snapshot
    response = await client.restore_snapshot(
        application_type='app',
        app_id='application_id',
        snapshot_id='snapshot_id',
        version_id='version_id'
    )
    
    print(f"Snapshot restored: {response.status}")
    
    # Restore a database snapshot
    response = await client.restore_snapshot(
        application_type='database',
        app_id='database_id',
        snapshot_id='snapshot_id',
        version_id='version_id'
    )
    
    print(f"Database snapshot restored: {response.status}")
```

## Snapshot-Datenstrukturen

### Snapshot

Das `Snapshot`-Objekt repräsentiert einen erstellten Snapshot:

| Property | Typ   | Beschreibung                               |
| -------- | ----- | ------------------------------------------ |
| `url`    | `str` | Download-URL für den Snapshot              |
| `key`    | `str` | Eindeutiger Identifikator für den Snapshot |

### SnapshotInfo

Das `SnapshotInfo`-Objekt repräsentiert Snapshot-Metadaten:

| Property     | Typ   | Beschreibung                                   |
| ------------ | ----- | ---------------------------------------------- |
| `id`         | `str` | Eindeutiger Snapshot-Identifikator             |
| `size`       | `str` | Größe des Snapshots                            |
| `created_at` | `str` | Zeitstempel der Snapshot-Erstellung (ISO 8601) |

## Best Practices

* **Automatische Backups**: Square Cloud erstellt automatisch tägliche Snapshots für deine Anwendungen und Datenbanken.
* **Unbegrenzte Snapshots**: Erstelle so viele manuelle Snapshots wie nötig, ohne zusätzliche Kosten.
* **Aufbewahrungsdauer**: Snapshots werden 30 Tage lang aufbewahrt.
* **Wiederherstellungszeit**: Der Wiederherstellungsvorgang dauert etwa 60 Sekunden, um sicherzustellen, dass alle Daten stabil sind.
* **Testen**: Bevor du einen Snapshot wiederherstellst, solltest du in Erwägung ziehen, zunächst eine neue Anwendung oder Datenbank zu erstellen, um den Wiederherstellungsprozess zu testen.

## Snapshot-Limits

* **Tägliche Snapshots pro Plan**: Jeder Plan kann `(RAM / 256) * 2` Snapshots pro Tag generieren
  * Beispiel: Hobby-Plan mit 2048MB = 16 tägliche Snapshots (480 pro Monat)
* **Aufbewahrung**: Alle Snapshots werden für die letzten 30 Tage aufbewahrt
* **Kosten**: Keine zusätzlichen Kosten für Snapshots
