/cappa

It is like Git, but for developement database

Primary LanguageGoApache License 2.0Apache-2.0

Cappa - Fast database snapshot and restore tool for development.

Cappa allows you to quickly snapshot / revert database when you are e.g. writing database migrations, switching branches or messing with SQL.

Warning : not stable yet + PostgreSQL only (at the moment).

Heavily inspired by fastmonkeys/stellar

Cappa allows you to take fast snapshots / restore of your development database.

Usage:
  cappa [command]

Available Commands:
  back        Reinstall a snapshot in development database
  delete      Delete snapshot
  execute     Execute sql from file (default '.cappa/execute.sql')
  grab        Grab backup file (.dump) from s3 bucket
  help        Help about any command
  list        List your snapshots
  restore     Restore from backup file
  snap        Create snapshot of development database
  version     Print the version number of Cappa

Flags:
      --config string   config file (default is .cappa.toml)
  -h, --help            help for cappa
  -v, --verbose         What's wrong ? Speak to me

Use "cappa [command] --help" for more information about a command.

How it works

Cappa works by storing copies of the database in the RDBMS (named as cappa_xxxx).

When restoring the database, Cappa simply copy the database making it lot faster than the usual SQL dump.

However, Cappa uses lots of storage space so you probably don't want to make too many snapshots or you will eventually run out of storage space.

Warning: Please don't use Cappa if you can't afford data loss. It's great for developing but not meant for production.

Installation

Package management is not taking care of for now (will be HomeBrew first).

Download binary (and install in your $PATH)

https://github.com/hbyio/cappa/releases

How to get started

Cappa looks for a DATABASE_URL key in your environment variables or in a local .cappa.toml config file.

e.g. : DATABASE_URL=postgres://admin:admin@127.0.0.1:5432/devdb

How to take a snapshot`

$ cappa snapshot

How to restore from a snapshot

$ cappa restore

Grab a fresh dump file from your s3 bucket (will be downloaded to a local .cappa directory)

$ cappa grab --bucket=safestorage --prefix=database/hourly

Restore from a dump file stored in a '.cappa' directory

$ cappa restore dump

If you load production data and need to run some sql before starting working (anonymisation)

$ cappa execute (will execute statements in an .cappa/execute.sql, line by line)

Common issues

Make sure you have the rights to create new databases.

If you are using PostreSQL, make sure you have a database named 'postgres'.

Todo

  • UX (wait animations, warnings, ..)
  • Tests
  • Mysql

"Cappa" ?

Because it wants to take great snapshots