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

> List, create and restore snapshots for applications and databases, or list every snapshot in the account.

```go theme={null}
client := rest.NewClient(os.Getenv("SQUARECLOUD_API_KEY"))
defer client.Close()

api := rest.New(client)
```

Snapshots come in three scopes: per application, per database, and account-wide.

## The Snapshot struct

Listing methods return `[]squarecloud.Snapshot`:

| Field      | Type     | Description                                        |
| ---------- | -------- | -------------------------------------------------- |
| `Name`     | `string` | Snapshot object name                               |
| `Size`     | `int`    | Size in bytes                                      |
| `Modified` | `string` | Last modification date                             |
| `Key`      | `string` | Signed query string used to build the download URL |

## Application snapshots

### Listing

```go theme={null}
snapshots, err := api.GetApplicationSnapshots("abc123def456abc123def456")
if err != nil {
	panic(err)
}

for _, snap := range snapshots {
	fmt.Println(snap.Name, snap.Size, snap.Modified)
}
```

### Creating

`api.CreateApplicationSnapshot(appID)` triggers a fresh snapshot and returns a `squarecloud.SnapshotCreated` with the signed download URL.

```go theme={null}
created, err := api.CreateApplicationSnapshot("abc123def456abc123def456")
if err != nil {
	panic(err)
}

fmt.Println(created.URL) // signed download URL
fmt.Println(created.Key)
```

### Restoring

`api.RestoreApplicationSnapshot(appID, snapshotID, versionID)` rolls the application back to a previous snapshot version.

```go theme={null}
err := api.RestoreApplicationSnapshot(
	"abc123def456abc123def456",
	"00000000-0000-4000-8000-000000000000",
	"abc123def4567890",
)
if err != nil {
	panic(err)
}
```

## Database snapshots

The database scope mirrors the application one:

```go theme={null}
snapshots, err := api.GetDatabaseSnapshots("abc123def456abc123def456")
if err != nil {
	panic(err)
}

created, err := api.CreateDatabaseSnapshot("abc123def456abc123def456")
if err != nil {
	panic(err)
}
fmt.Println(created.URL)

err = api.RestoreDatabaseSnapshot(
	"abc123def456abc123def456",
	"00000000-0000-4000-8000-000000000000_mongo",
	"v1",
)
if err != nil {
	panic(err)
}
```

## Listing snapshots account-wide

`api.UserSnapshots(scope)` returns every snapshot you own across all your applications or databases. The scope is one of the `squarecloud.SnapshotScope*` constants:

```go theme={null}
appSnapshots, err := api.UserSnapshots(squarecloud.SnapshotScopeApplications)
if err != nil {
	panic(err)
}

dbSnapshots, err := api.UserSnapshots(squarecloud.SnapshotScopeDatabases)
if err != nil {
	panic(err)
}
```

<Note>
  Account-wide snapshot listing requires an active paid plan. Each plan also has a **daily snapshot quota** — once it's exhausted, creation fails with the `DAILY_SNAPSHOTS_LIMIT_REACHED` code, distinct from the generic `KEEP_CALM` rate-limit error.
</Note>
