Introducing postgres-backup: A docker image that allows us to clone postgres databases for easy testing.
We’ve recently been working on reorganizing some of the underlying data model for user accounts and access in Ployst.
This last weekend I wanted to test run the various migrations using (our very limited) production data.
I wanted to be able to take a postgres data source, dump it and then load it as the data source of a different container. I could then run the db migrations against the new container.
Given two database containers named
Running this command would create a backup of
main db and load it into
To get a nice workflow for this kind of test in kubernetes, I had to script the following steps:
- Create a new RC owning a postgres db
- Run a job using the ployst/postgres-backup image with env vars that direct it to dump from the source db service and load into the target.
- Get access to the container
Step 3 could be exposing it externally if you’re feeling adventurous (I can’t say I’m brave enough to expose dbs to the public network). We use an openvpn image to connect to the container network directly.
I can foresee the ployst/postgres-backup image evolving to be able to use an existing dump (eg if you’re OK with last night’s backup).
I’d also like to introduce anonymizing of data into the workflow - though we’ll do that via a new image.