snapshots
Creates, updates, deletes, gets or lists a snapshots resource.
Overview
| Name | snapshots |
| Type | Resource |
| Id | netlify.database.snapshots |
Fields
The following fields are returned by SELECT queries:
- list
| Name | Datatype | Description |
|---|---|---|
id | string | The unique identifier of the snapshot |
source_branch_id | string | The ID of the branch that was snapshotted |
created_at | string (dateTime) | When the snapshot was created |
expires_at | string (dateTime) | When the snapshot expires |
manual | boolean | Whether this snapshot was manually created |
metadata | object | Metadata associated with a snapshot |
timestamp | string (dateTime) | The point-in-time timestamp of the snapshot |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
list | select | site_id | Returns all snapshots for the site's database. | |
create | insert | site_id | Creates a point-in-time snapshot of a database branch. Defaults to the production branch if no branch name is specified. | |
delete | delete | site_id, snapshot_id | Deletes a database snapshot. | |
restore | exec | site_id, snapshot_id | Restores 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.
| Name | Datatype | Description |
|---|---|---|
site_id | string | |
snapshot_id | string | The snapshot ID to restore |
SELECT examples
- list
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
- create
- Manifest
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
;
# Description fields are for documentation purposes
- name: snapshots
props:
- name: site_id
value: "{{ site_id }}"
description: Required parameter for the snapshots resource.
- name: branch_id
value: "{{ branch_id }}"
description: |
The ID of the branch to snapshot. Defaults to "production" if not specified.
- name: name
value: "{{ name }}"
description: |
A name for the snapshot
- name: metadata
description: |
Metadata associated with a snapshot
value:
deploy: "{{ deploy }}"
source: "{{ source }}"
DELETE examples
- delete
Deletes a database snapshot.
DELETE FROM netlify.database.snapshots
WHERE site_id = '{{ site_id }}' --required
AND snapshot_id = '{{ snapshot_id }}' --required
;
Lifecycle Methods
- restore
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 }}"
}'
;