Quick, easy & simple way to stash your database state and reapply.
Install mysql-client package via Brew:
motomod@mac:~$ brew install mysql-clientDownload the Go package from here and install.
Install the mysql-client & golang via your favourite package manager:
motomod@ubuntu:~$ apt-get install mysql-client golangYou'll also need bash but I'll assume that you probably already have this.
Clone this repo to your computer:
motomod@ubuntu:~$ git clone git@github.com:motomod/mysql-stash.gitMove into the new directory:
motomod@ubuntu:~$ cd mysql-stashInstall the package, this will plop a binary into your bin path:
motomod@ubuntu:~$ make installYou will need to ensure that you're GOPATH is set in your bash, zsh (or whatever) profile to be able to execute the binary.
To use this application you'll need to create a configuration file located at
~/.config/mysql-stash/config.yml, see bundled
example.
Root properties:
databases- An array of a database objects, keys are the name of the database:- host
- port
- database
- user
- pass
You can access the application by running:
motomod@ubuntu:~$ mysql-stashProviding no arguments will result in a message to come back here, hiya 👋
This command makes a snapshot of your current database, ready for you to reapply at a later date.
motomod@ubuntu:~$ mysql-stash stash <db name> <stash name><db name>the name of the database that you wish to create a stash for, must match one of the keys defined in your configuration or beallwhich will stash all of your databases.<stash name>is the name that you wish to give your stash, you'll need this later when reapplying.
Stashes are standard SQL dumps from mysqldump and are located in the same path as your configuration.
motomod@ubuntu:~$ mysql-stash apply <db name> <stash name><db name>the name of the database that you wish to apply a stash for, must match one of the keys defined in your configuration or beallwhich will apply the stashes for all of your databases.<stash name>name of the stash that you wish to reapply.
Stashes are piped to the system mysql command in bash.
List all of the stashes that you've created.
motomod@ubuntu:~$ mysql-stash listIf you want to export or view the SQL generated by a stash then:
motomod@ubuntu:~$ mysql-stash view <db name> <stash name><db name>the name of the database for the stash you wish to view, cannot beallthis time, soz.<stash name>name of the stash that you wish to view.