2016-10-26 02:20:24 +00:00
---
2020-09-01 15:14:13 +00:00
layout: commands
2020-04-07 18:55:19 +00:00
page_title: 'Commands: Snapshot Save'
2023-01-26 18:42:13 +00:00
description: |
The `consul snapshot save` command retrieves a point-in-time snapshot of the state of the Consul servers and saves it to a specified location. Data saved in snapshots includes key/value entries, registered services in the catalog, prepared queries, sessions, and ACLs from a saved snapshot.
2016-10-26 02:20:24 +00:00
---
# Consul Snapshot Save
Command: `consul snapshot save`
2023-01-25 16:52:43 +00:00
Corresponding HTTP API Endpoint: [\[GET\] /v1/snapshot](/consul/api-docs/snapshot#generate-snapshot)
2022-01-10 17:40:11 +00:00
2016-10-26 02:20:24 +00:00
The `snapshot save` command is used to retrieve an atomic, point-in-time snapshot
of the state of the Consul servers which includes key/value entries,
service catalog, prepared queries, sessions, and ACLs. The snapshot is saved to
the given file.
If ACLs are enabled, a management token must be supplied in order to perform
2019-02-20 16:42:38 +00:00
a snapshot save.
2016-10-26 02:20:24 +00:00
2021-01-06 18:56:40 +00:00
-> Note that saving a snapshot involves the server process writing the snapshot to a
2023-05-09 19:28:52 +00:00
temporary file on-disk before sending that file to the CLI client. Upon successful completion,
Consul removes the temporary file. The default location of the temporary file
2021-01-06 18:56:40 +00:00
can vary depending on operating system, but typically is `/tmp`. You can get more detailed
information on default locations in the Go documentation for [os.TempDir](https://golang.org/pkg/os/#TempDir).
If you need to change this location, you can do so by setting the `TMPDIR` environment
variable for the Consul server processes. Keep in mind that setting the environment variable for
the CLI client attempting to perform a snapshot save will have no effect. It _must_ be set in
the context of the server process. If you're using Systemd to manage your Consul server
processes, then adding `Environment=TMPDIR=/path/to/dir` to your Consul unit file will work.
2023-05-09 19:28:52 +00:00
As a result of the Raft snapshot, Consul also saves one snapshot file at `data_dir/raft/snapshots`.
2021-01-06 18:56:40 +00:00
2023-01-25 16:52:43 +00:00
The table below shows this command's [required ACLs](/consul/api-docs/api-structure#authentication). Configuration of
[blocking queries](/consul/api-docs/features/blocking) and [agent caching](/consul/api-docs/features/caching)
2022-01-10 21:44:56 +00:00
are not supported from commands, but may be from the corresponding HTTP endpoint.
| ACL Required |
| ------------ |
| `management` |
2016-10-26 02:20:24 +00:00
## Usage
Usage: `consul snapshot save [options] FILE`
#### API Options
2020-04-07 18:55:19 +00:00
@include 'http_api_options_client.mdx'
2020-04-07 23:56:08 +00:00
2020-04-07 18:55:19 +00:00
@include 'http_api_options_server.mdx'
2016-10-26 02:20:24 +00:00
2023-09-01 04:53:44 +00:00
- `-append-filename=<value>` - Value can be - version,dc,node,status
Adds consul version, datacenter name, node name, and status (leader/follower)
to the file name before the extension separated by `-`
2016-10-26 02:20:24 +00:00
## Examples
To create a snapshot from the leader server and save it to "backup.snap":
2020-05-19 18:32:38 +00:00
```shell-session
2016-10-26 02:20:24 +00:00
$ consul snapshot save backup.snap
Saved and verified snapshot to index 8419
```
By default, snapshots are taken using a consistent mode that forwards requests
to the leader and the leader verifies it is still in power before taking the
snapshot.
After the snapshot is written to the given file it is read back and verified for
integrity.
To create a potentially stale snapshot from any available server, use the stale
2017-02-10 01:00:38 +00:00
consistency mode:
2016-10-26 02:20:24 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2016-10-26 02:20:24 +00:00
$ consul snapshot save -stale backup.snap
# ...
```
2023-09-06 10:19:25 +00:00
This is useful for situations where a cluster is in a degraded state and no
leader is available. To target a specific server for a snapshot, you can run
the `consul snapshot save` command on that specific server.
To create snapshot file with consul version and datacenter run
2023-09-01 04:53:44 +00:00
```shell-session
2023-09-06 10:19:25 +00:00
$ consul snapshot save -append-filename version,dc backup.snap
2023-09-01 04:53:44 +00:00
#...
```
2023-09-06 10:19:25 +00:00
File name created will be like backup-%CONSUL_VERSION%-%DC_NAME%.snap
2023-09-01 04:53:44 +00:00
example - backup-1.17.0-dc1-local-machine-leader.tgz
2023-09-06 10:19:25 +00:00
Note Version is always the leader's consul version
2016-10-26 02:20:24 +00:00
2023-01-25 16:52:43 +00:00
Please see the [HTTP API](/consul/api-docs/snapshot) documentation for
2016-10-26 02:20:24 +00:00
more details about snapshot internals.