Docker + Backup = Dockup

Learn how to automate Docker backups with Dockup. This guide covers setting up Dockup, backing up Docker volumes and databases, restoring data, and the benefits of using Dockup for Docker container backups.

Docker + Backup = Dockup

Yesterday, a colleague called me out 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 set to cleanup.

After some investigating, it turns out that Dockup already supports Cron jobs but was not documented, so 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, Dockup will back up your data to S3 until the cows come home or your credit card refuses, whichever comes first.

To prevent this, I set up a retention time inside 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 whether to keep the cron job running in the container or remove it and create a cronjob on my Docker Host that 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 into the backup strategy to ensure all my configurations are backed up as well.

FAQ Section: Docker Backup with Dockup

What is Dockup, and how does it work with Docker for backups?
Dockup is an open-source tool designed to automate the backup and restoration of Docker containers and their data. It works by creating scheduled backups of container volumes and databases, storing them in cloud services like Amazon S3 or Google Cloud Storage. Dockup can be easily integrated into your Docker environment, ensuring that your data is securely backed up and recoverable in case of failure.

How can I set up Dockup to back up my Docker containers?
To set up Dockup, you first need to add Dockup as a service in your docker-compose.yml file. Configure the environment variables within the file to specify backup schedules, storage destinations, and the volumes or databases you want to back up. Once set up, Dockup will automatically handle the backup process according to your specified configuration.

What types of data can Dockup back up?
Dockup can back up a variety of data types, including Docker volumes, databases like MySQL and PostgreSQL, and application data stored within containers. By specifying the relevant volumes or databases in the docker-compose.yml file, Dockup ensures that all critical data associated with your Docker containers is backed up.

How do I restore data from a Dockup backup?
Restoring data from a Dockup backup is straightforward. You can run Dockup in restore mode by setting the appropriate environment variables in your docker-compose.yml file or using command-line options. Dockup will retrieve the specified backup from your cloud storage and restore the data to the target container, allowing you to quickly recover from data loss.

What are the benefits of using Dockup for Docker backups?
Dockup offers several benefits, including automated and scheduled backups, integration with popular cloud storage services, and ease of use with Docker Compose. It simplifies the backup process, ensuring that your Docker environments are protected without requiring extensive manual intervention. Additionally, Dockup's open-source nature allows for customization to meet specific backup needs.

Follow me

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