Skip to main content
Snapshots are archives of an app’s or database’s storage. Apps and databases share the same four methods:
  • c.Apps.Snapshots: List(ctx, appID), Create(ctx, appID), Restore(ctx, appID, name, versionID), RestoreState(ctx, appID)
  • c.Databases.Snapshots: List(ctx, databaseID), Create(ctx, databaseID), Restore(ctx, databaseID, name, versionID), RestoreState(ctx, databaseID)
How many snapshots you can create per day depends on your plan (see Limits). Each snippet below runs on its own inside this program: paste one at a time into main and run goimports (see Running the examples).

Listing snapshots

When snapshot storage cannot answer, List returns 503 SNAPSHOTS_UNAVAILABLE instead of an empty list. The SDK does not retry it: wait about 30 seconds and list again.

Creating a snapshot

Create waits for the snapshot (without a ctx deadline, at least 2 minutes before timing out). A large snapshot may not finish in time: the API then answers 202 and the SDK returns a SnapshotCreated with Pending set to true and a nil error. The snapshot keeps generating and shows up in List on its own, usually within 2 minutes.
With an API key that lacks the snapshots:read scope, a finished snapshot comes back with Pending set to false and an empty URL and Key. Create returns 409 RESTORE_IN_PROGRESS while a restore runs, and 503 CLUSTER_MAINTENANCE_TRY_LATER during maintenance: try again in a few minutes.
Never call Create again to check on a pending snapshot: it starts a new one and counts against the plan’s daily snapshot quota. Poll List instead.

Restoring a snapshot

Restore(ctx, id, name, versionID) takes the Name and VersionID of a listed snapshot and returns a SnapshotRestored. Without a ctx deadline, it waits at least 2 minutes before timing out. A restore that takes longer than about 90 seconds keeps running after the call returns: the API answers 202 SNAPSHOT_RESTORE_PROCESSING, and the SDK returns a SnapshotRestored with Pending set to true and a nil error. Follow it with RestoreState until it ends.
Never call Restore again to check on a pending restore. The first one is still running: poll RestoreState instead.
The SDK retries none of them.

Following a restore

RestoreState(ctx, id) reports the last restore of the app or database as a SnapshotRestoreState. It allows 30 calls a minute, so poll it every few seconds, as in the example above. While a restore runs, Status also reports Restoring as true.

Downloading a snapshot

c.DownloadSnapshot(ctx, url, w) streams a snapshot file from its signed url (from List or Create) into any io.Writer. It does not call the API: the API key is never sent to the storage host, and the URL never appears in the returned error. Nothing is buffered in memory, and there is no default deadline (bound or cancel it with ctx). A network error before the response is retried like any GET. The URL is valid for 1 hour, so download soon after List or Create.
An expired or invalid URL returns an *APIError with the storage host’s HTTP status and UNKNOWN_ERROR. A URL that cannot be parsed, and an error of your io.Writer, are returned as plain errors.

Account snapshots

c.Account.Snapshots(ctx, scope) lists the snapshots of all your apps ("" or squarecloud.SnapshotScopeApplications) or of all your databases (squarecloud.SnapshotScopeDatabases). It needs an active plan and is limited to 3 calls a minute (429 RATE_LIMITED).

Limits

  • Create is limited to one call per 180 seconds and to a daily quota that depends on the plan: going over the quota is 429 DAILY_SNAPSHOTS_LIMIT_REACHED.
  • RestoreState is limited to 30 calls a minute.
  • While a restore runs, these calls return 409 RESTORE_IN_PROGRESS: start, stop, restart and delete of the app, start, stop and delete of the database, and snapshot Create and Restore.

Next steps

Databases

Create and manage databases.

Snapshot API reference

The REST endpoints behind these methods.

Snapshots from the CLI

The same actions from the terminal.