Skip to content

Quick Start

In this example we will create and restore a database snapshots.

config init

Run the config init command to create an example configuration at ~/.config/dbsnapper/dbsnapper.yml

dbsnapper config init

Configuration file initialized to default values

secret_key: d3d234bc83dd4efe7b7329855ba0acc2
working_directory: /Users/joescharf/.dbsnapper
    postgres: postgres:latest

The default configuration uses the PostgreSQL engine with Docker. Check the Datbase Engines documentation for other database options and how to configure them.

config check

Next, we can check our configuration and required dependencies. This run some checks to verify the configuration file is valid, Docker is installed, and the specified Docker images exist locally.

dbsnapper config check

DBSnapper config check output

  Checking DBSnapper Configuration
✅ Config file ( /Users/joescharf/.config/dbsnapper/dbsnapper.yml ) found and loaded
🔵 Postgres Docker Engine (pgdocker)
  ✅ Docker client connected
  ✅ docker.images set in config file
  ✅ docker.images.mysql set in config file
    ✅ Found Docker image: postgres:latest
🔵 Postgres Local Engine (pglocal)
  ✅ psql found at /Applications/
  ✅ pg_dump found at /Applications/
  ✅ pg_restore found at /Applications/
🔵 Mysql Docker Engine (mydocker)
  ✅ Docker client connected
  ✅ docker.images set in config file
  ✅ docker.images.mysql set in config file
    ✅ Found Docker image: mysql:8.0-oracle
✅ All supported database engines configured
✅ DBSnapper Cloud connected

✅ Configuration OK

Add target definitions

Add one or more databse targets to configuration file. Here we define an app target with a src_url specifying the source database and a dst_url specifying the destination database

Defining an app target definition

    src_url: postgresql://postgres:postgres@localhost:15432/app?sslmode=disable
    dst_url: postgresql://postgres:postgres@localhost:15432/app_snap?sslmode=disable


A database specified on the dst_url will be DROPPED and RECREATED when the load command is used

List targets

Now that we have a target defined, we can list all targets with:

dbsnapper targets

This command will also check the size and connectivity status for each target defined in the configuration file.

Build a snapshot

Now we're ready to create our first snapshot of the app target which can be done with the build command:

dbsnapper build app

This will connect to the database using the native dump utility and will create a dump of all data in the database.

When this is finished you can list all snapshots for the app target with:

dbsnapper target app

List snapshots for a target

Once you've successfully built a snapshot, you can list all the sanpshots for a target with the following command (note the singular target command):

dbsnapper target app

Load a snapshot

If a dst_url is defined in the target definition, you can load a snapshot to the destination using the index on the snapshot list.

dbsnapper load app 0


Remember, the database specifid on dst_url will be DROPPED and a new empty database with the same name will be CREATED prior to loading the data from the snapshot!

Last update: December 13, 2022