Skip to main content
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:
FieldTypeDescription
NamestringSnapshot object name
SizeintSize in bytes
ModifiedstringLast modification date
KeystringSigned query string used to build the download URL

Application snapshots

Listing

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.
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.
err := api.RestoreApplicationSnapshot(
	"abc123def456abc123def456",
	"00000000-0000-4000-8000-000000000000",
	"abc123def4567890",
)
if err != nil {
	panic(err)
}

Database snapshots

The database scope mirrors the application one:
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:
appSnapshots, err := api.UserSnapshots(squarecloud.SnapshotScopeApplications)
if err != nil {
	panic(err)
}

dbSnapshots, err := api.UserSnapshots(squarecloud.SnapshotScopeDatabases)
if err != nil {
	panic(err)
}
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.