Skip to main content

snapshots

Creates, updates, deletes, gets or lists a snapshots resource.

Overview

Namesnapshots
TypeResource
Idnetlify.database.snapshots

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringThe unique identifier of the snapshot
source_branch_idstringThe ID of the branch that was snapshotted
created_atstring (dateTime)When the snapshot was created
expires_atstring (dateTime)When the snapshot expires
manualbooleanWhether this snapshot was manually created
metadataobjectMetadata associated with a snapshot
timestampstring (dateTime)The point-in-time timestamp of the snapshot

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectsite_idReturns all snapshots for the site's database.
createinsertsite_idCreates a point-in-time snapshot of a database branch. Defaults to the production branch if no branch name is specified.
deletedeletesite_id, snapshot_idDeletes a database snapshot.
restoreexecsite_id, snapshot_idRestores a snapshot to a database branch. Defaults to the production branch if no branch_name is specified.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
site_idstring
snapshot_idstringThe snapshot ID to restore

SELECT examples

Returns all snapshots for the site's database.

SELECT
id,
source_branch_id,
created_at,
expires_at,
manual,
metadata,
timestamp
FROM netlify.database.snapshots
WHERE site_id = '{{ site_id }}' -- required
;

INSERT examples

Creates a point-in-time snapshot of a database branch. Defaults to the production branch if no branch name is specified.

INSERT INTO netlify.database.snapshots (
branch_id,
name,
metadata,
site_id
)
SELECT
'{{ branch_id }}',
'{{ name }}',
'{{ metadata }}',
'{{ site_id }}'
RETURNING
id,
source_branch_id,
created_at,
expires_at,
manual,
metadata,
timestamp
;

DELETE examples

Deletes a database snapshot.

DELETE FROM netlify.database.snapshots
WHERE site_id = '{{ site_id }}' --required
AND snapshot_id = '{{ snapshot_id }}' --required
;

Lifecycle Methods

Restores a snapshot to a database branch. Defaults to the production branch if no branch_name is specified.

EXEC netlify.database.snapshots.restore
@site_id='{{ site_id }}' --required,
@snapshot_id='{{ snapshot_id }}' --required
@@json=
'{
"branch_id": "{{ branch_id }}"
}'
;