MySQL-Stash is a small, light-weight utility for quickly backing up and restoring your MySQL database with data. This has helped me with testing new features during development where I can easily switch between datasets.
- Create database stashes
- Apply database stashes
- List database stashes
- View database stashes
- Multiple database support
- Python 2.7 (may work on later versions, but untested)
- Python packages (yaml, subprocess)
$ sudo apt install python2.7 mysql-client
Databases need to be configured before running the app. Databases need to be configured in the databases.yml file in the root directory. See the example for help.
$ python app.py [-h] database [action] stash_name
database - The name given to the database in the databases.yml file. This can be 'all' to backup all databases at once. action - 'create'/'apply'/'view'/'list'
Creating a stash
To make a stash of the current database with the name of "feature2" you would run:
$ python app.py exampledb create feature2
View a list of previously created stashes
$ python app.py exampledb list
Apply a stash
To apply a created stash you would run:
$ python app.py exampledb apply feature2
View a stash
View a previously created stash, doing this will show you the SQL required to recreate your database:
$ python app.py exampledb view feature2
I had hoped to not run a system command to dump the database, but mysqldump takes a lot of things into consideration when dumping database (like foreign keys) so I will use that for now.