Docker + Backup = Dockup

Docker + Backup = Dockup

Yesterday, I was called out by a colleague after he discovered I was backing up my Docker environments to Amazon S3 with some bash scripts and a crontab entry. This is a working solution but he asked ever so politely why I was not running this in a Docker container? As I buried my head in shame I decided to get cracking and move my backups into a container.

He informed me that he started his Docker project recently and was using
Tutum's Dockup Docker + Backup = Dockup to perform Docker volume backups. I researched Dockup and dug through the code and decided it was a good match for my projects.

Dockup backups up your Docker Container volumes and is really easy to configure and get running. Configuring Dockup is straightforward and all the settings are stored in a configuration file env.txt. Here we define what volumes from what containers to backup and to which Amazon S3 bucket to store the backup.

env.txt:

AWS_ACCESS_KEY_ID=<key_here>
AWS_SECRET_ACCESS_KEY=<secret_here>
AWS_DEFAULT_REGION=us-east-1
BACKUP_NAME=mysql
PATHS_TO_BACKUP=/etc/mysql /var/lib/mysql
S3_BUCKET_NAME=docker-backups.example.com
RESTORE=false

I initially ran Dockup on this blog and it created a Tar file in my Amazon S3 bucket and exited as the docker run command is setup to cleanup. After some investigating it turns out that Dockup already supports Cron jobs but was not documented so as in true Open Source spirit I created a Pull Request on the Dockerup project and added instructions on how to run and use the CRON_TIME variable.

S3 Backup Retention Time

If you are running this as a cron job then Dockup will backup your data into S3 until the cows come home or your credit card refuse, whichever comes first. To prevent this I setup a retention time inside of S3 to ensure backups older than N days old will be automatically purged by S3. Inside your S3 bucket properties navigate to Lifecycle and create a rule to remove objects after a certain amount of time. I've selected 120 days in my example.

S3 Backup Retention

Next Steps

I haven't decided if I will keep the cron job running in the container or remove the container and create a cronjob on my Docker Host which launches the container at backup time. Either way it is only a small detail. Next, I will try to incorporate all my docker-compose files also in the backup strategy to ensure all my configurations are backed up as well.

Follow me

If you liked this article be sure to Follow Me on Twitter to stay updated!