A PostgreSQL snapshot tool that effortlessly captures and restores precise snapshots of your database.
The snapvault CLI tool is intended to be used during local development as an easy way to capture and restore snapshots of the database, making it possible to quickly restore the database to a previous state.
It uses the template functionality in Postgres to create clones of databases, which is faster than using pg_dump
/pg_restore
. This means that all clones are actually stored as separate databases on the same Postgres server as the original database.
It supports basic commands such as save
, restore
, list
and delete
:
$ snapvault save <snapshot_name>
$ snapvault restore <snapshot_name>
$ snapvault list
$ snapvault delete <snapshot_name>
Snapvault is similar to projects like DLSR and Stellar. However, unlike those projects snapvault is written in Go and delivered as a standalone binary, making it possible to use the tool without having to rely on Python or managing any other dependencies.
Binaries are available in both Intel and ARM versions for OSX/Darwin, Linux and Windows and can be found under the Releases section.
$ brew tap cotramarko/tools
$ brew install snapvault
OSX/Darwin & Linux
# Change binary depending on your platform
# Linux:
# snapvault_Linux_arm64
# snapvault_Linux_i386
# snapvault_Linux_x86_64
# OSX:
# snapvault_Darwin_arm64
# snapvault_Darwin_x86_64
# Bash:
$ TARGET=snapvault_Darwin_x86_64
# Fish:
$ set TARGET snapvault_Darwin_x86_64
# Download binary and make it executable
$ sudo curl -fsSL -o /usr/local/bin/snapvault https://github.com/cotramarko/snapvault/releases/latest/download/$TARGET
$ sudo chmod +x /usr/local/bin/snapvault
Windows
Download and unzip the archive for your target platform. The unzipped archive contains an .exe
of the binary.
The database URL can be provided in multiple ways
Create a snapvault.toml
file containing the database URL
url = "postgres://acmeuser:acmepassword@localhost:5432/acmedb"
The URL will be used whenever snapvault
is in the same directory as the file.
Another option is to set the DATABASE_URL
environment variable to the database URL
# Bash:
$ export DATABASE_URL=postgres://acmeuser:acmepassword@localhost:5432/acmedb
# Fish:
$ set -x DATABASE_URL postgres://acmeuser:acmepassword@localhost:5432/acmedb
If both the DATABASE_URL
is set and a snapvault.toml
file is present then the snapvault.toml
file will be preferred.
Another option is to explicitly pass the database URL with the --url
flag whenever running a snapvault command
$ snapvault list --url=postgres://acmeuser:acmepassword@localhost:5432/acmedb
The --url
flag will always override any of the other ways of specifying the URL.
$ snapvault save fix/foobar
Created snapshot fix/foobar
$ snapvault restore fix/foobar
Restored snapshot fix/foobar
$ snapvault list
╭────────────┬──────────────────────┬─────────╮
│ NAME │ CREATED │ SIZE │
├────────────┼──────────────────────┼─────────┤
│ fix/foobar │ 2024-06-23T15:37:39Z │ 7561 kB │
╰────────────┴──────────────────────┴─────────╯
$ snapvault delete fix/foobar
Deleted snapshot fix/foobar