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

> Anwendungs-Snapshots auflisten, erstellen, herunterladen und wiederherstellen — der v4-Ersatz für die veraltete Backup-API.

<Info>
  Snapshots ersetzen die v3-`backup`- / `backups`-API. `app.backup` und `app.backups` werden in v4 weiterhin exportiert, geben aber eine Deprecation-Warnung aus und leiten an `app.snapshots` weiter. Aktualisiere deinen Code auf den neuen Namen.
</Info>

`app.snapshots` stellt das [`SnapshotsModule`](https://github.com/squarecloudofc/sdk-api-js/blob/main/src/modules/snapshots.ts) bereit.

```typescript theme={null}
const app = await api.applications.fetch("abc123def456abc123def456");
app.snapshots; // SnapshotsModule
```

## Snapshots auflisten

`app.snapshots.list()` liefert ein Array von `Snapshot`-Instanzen.

```typescript theme={null}
const snapshots = await app.snapshots.list();

for (const snap of snapshots) {
    console.log(snap.url);          // signierte Download-URL (30 Tage gültig)
    console.log(snap.size);         // Bytes
    console.log(snap.modifiedAt);   // Date
    console.log(snap.key);          // signierter Query-String
}
```

Jeder Snapshot kann direkt heruntergeladen werden:

```typescript theme={null}
const buffer = await snapshots[0].download();
```

## Einen neuen Snapshot erstellen

`app.snapshots.create()` löst einen frischen Snapshot aus und liefert die signierte URL und den Key.

```typescript theme={null}
const fresh = await app.snapshots.create();
console.log(fresh.url); // 30 Tage gültig
console.log(fresh.key);
```

## Download in einem Schritt

`app.snapshots.download()` erstellt einen Snapshot und lädt ihn als `Buffer` herunter.

```typescript theme={null}
import { writeFile } from "node:fs/promises";

const buffer = await app.snapshots.download();
await writeFile("./backup.zip", buffer);
```

## Aus einem Snapshot wiederherstellen

`app.snapshots.restore({ snapshotId, versionId })` setzt die Anwendung auf eine frühere Snapshot-Version zurück.

```typescript theme={null}
await app.snapshots.restore({
    snapshotId: "00000000-0000-4000-8000-000000000000",
    versionId: "abc123def4567890",
});
```

| Feld         | Typ      | Beschreibung                                    |
| ------------ | -------- | ----------------------------------------------- |
| `snapshotId` | `string` | Snapshot-Bezeichner (UUID v4)                   |
| `versionId`  | `string` | Von `list()` zurückgegebener Versionsbezeichner |

## Snapshots kontoweit auflisten

`api.user.snapshots(scope)` liefert jeden Snapshot, den du besitzt, über alle deine Anwendungen oder Datenbanken hinweg.

```typescript theme={null}
const appSnapshots = await api.user.snapshots("applications");
const dbSnapshots  = await api.user.snapshots("databases");
```

<Note>
  `api.user.snapshots()` erfordert ein aktives kostenpflichtiges Abonnement.
</Note>
