consul/website/content/api-docs/snapshot.mdx

119 lines
4.6 KiB
Plaintext
Raw Permalink Normal View History

2017-04-04 16:33:22 +00:00
---
layout: api
page_title: Snapshot - HTTP API
description: |-
The /snapshot endpoints save and restore Consul's server state for disaster
recovery.
---
# Snapshot HTTP Endpoint
The `/snapshot` endpoints save and restore the state of the Consul
servers for disaster recovery. Snapshots include all state managed by Consul's
Raft [consensus protocol](/consul/docs/architecture/consensus).
2017-04-04 16:33:22 +00:00
## Generate Snapshot
This endpoint generates and returns an atomic, point-in-time snapshot of the
Consul server state.
Snapshots are exposed as gzipped tar archives which internally contain the Raft
metadata required to restore, as well as a binary serialized version of the
Consul server state. The contents are covered internally by SHA-256 hashes.
These hashes are verified during snapshot restore operations. The structure of
the archive is internal to Consul and not intended to be used other than for
restore operations. The archives are not designed to be modified before a
restore.
2020-04-06 20:27:35 +00:00
| Method | Path | Produces |
| :----- | :---------- | ------------------------ |
| `GET` | `/snapshot` | `200 application/x-gzip` |
2017-04-04 16:33:22 +00:00
The table below shows this endpoint's support for
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2017-04-04 16:33:22 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ------------ |
| `NO` | `default,stale` | `none` | `management` |
2017-04-04 16:33:22 +00:00
The corresponding CLI command is [`consul snapshot save`](/consul/commands/snapshot/save).
2022-01-10 19:21:32 +00:00
### Query Parameters
2017-04-04 16:33:22 +00:00
- `dc` `(string: "")` - Specifies the datacenter to query. This will default
to the datacenter of the agent being queried.
2017-04-04 16:33:22 +00:00
- `stale` `(bool: false)` - Specifies that any follower may reply. By default
requests are forwarded to the leader. Followers may be faster to respond, but
may have stale data. To support bounding the acceptable staleness of
snapshots, responses provide the `X-Consul-LastContact` header containing the
time in milliseconds that a server was last contacted by the leader node. The
`X-Consul-KnownLeader` header also indicates if there is a known leader. These
can be used by clients to gauge the staleness of a snapshot and take
appropriate action. The stale mode is particularly useful for taking a
snapshot of a cluster in a failed state with no current leader.
### Sample Request
With a custom datacenter:
2020-05-19 18:32:38 +00:00
```shell-session
$ curl http://127.0.0.1:8500/v1/snapshot?dc=my-datacenter --output snapshot.snap
2017-04-04 16:33:22 +00:00
```
The above example results in a tarball named `snapshot.snap` in the current working directory.
2017-04-04 16:33:22 +00:00
In addition to the Consul standard stale-related headers, the `X-Consul-Index`
header will contain the index at which the snapshot took place.
## Restore Snapshot
This endpoint restores a point-in-time snapshot of the Consul server state.
Restores involve a potentially dangerous low-level Raft operation that is not
designed to handle server failures during a restore. This operation is primarily
intended to recover from a disaster. It restores your configuration into a fresh
cluster of Consul servers as long as your new cluster runs the same Consul
version as the cluster that originally took the snapshot.
2017-04-04 16:33:22 +00:00
2020-04-06 20:27:35 +00:00
| Method | Path | Produces |
| :----- | :---------- | ----------------------------- |
| `PUT` | `/snapshot` | `200 text/plain (empty body)` |
2017-04-04 16:33:22 +00:00
The table below shows this endpoint's support for
[blocking queries](/consul/api-docs/features/blocking),
[consistency modes](/consul/api-docs/features/consistency),
[agent caching](/consul/api-docs/features/caching), and
[required ACLs](/consul/api-docs/api-structure#authentication).
2017-04-04 16:33:22 +00:00
| Blocking Queries | Consistency Modes | Agent Caching | ACL Required |
| ---------------- | ----------------- | ------------- | ------------ |
| `NO` | `none` | `none` | `management` |
2020-04-06 20:27:35 +00:00
The corresponding CLI command is [`consul snapshot restore`](/consul/commands/snapshot/restore).
2022-01-10 19:21:32 +00:00
### Query Parameters
2017-04-04 16:33:22 +00:00
- `dc` `(string: "")` - Specifies the datacenter to query. This will default
to the datacenter of the agent being queried.
### Request Body
The body of the request should be a snapshot archive returned by a previous
call to [generate snapshot](#generate-snapshot).
2017-04-04 16:33:22 +00:00
### Sample Request
2020-05-19 18:32:38 +00:00
```shell-session
2017-04-04 16:33:22 +00:00
$ curl \
--request PUT \
--data-binary @snapshot.snap \
http://127.0.0.1:8500/v1/snapshot
2017-04-04 16:33:22 +00:00
```
~> Some tools default to www/encoded uploads. Consul expects the snapshot to be
in pure binary form.