One part of setting up my online presence naturally includes getting backups going.
Since I'm trying to keep everything containerized, I did some research into what Amazon S3 backup solutions are out there. I found a popular project called dockup that basically does everything I wanted to have done.
However, upon looking at what I had to configure, I thought it could be simpler.
In order to get dockup working, you have to mount the volumes you want to backup to some arbitrary place in the filesystem, and provide the following environment variables:
So, in English, given a bunch of directories (specified in PATHS_TO_BACKUP), dockup will create a timestamped backup (using the name BACKUP_NAME) in the bucket S3_BUCKET_NAME.
My ideal backup image would work different in a few ways.
First, I want a separate backup for each of my apps. At any given time, I'm not sure which services I will be running. Maybe I'll stop the blog and keep the git repo running. Or maybe I'll add a new service. I want to keep the data for each of those services separate.
Next, I shouldn't have to specify which directories I want to backup. I could just put my volumes somewhere specific, like /backups.
Finally, the structure of the backup directory can contain the bucket and name. For example, any data in the directory /backups/app-backups/blog-data will be bundled and named blog-data and placed in the app-backups bucket.
With those ideas in mind, I made my own image called s3-backup. The following block is now live in my Docker Compose file:
backups:
image: ptrvldz/s3-backup:0.1
container_name: backups
restart: always
volumes:
- ghost:/backups/ptrvldz-backups/ghost-blog
- gogs:/backups/ptrvldz-backups/gogs
environment:
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
- AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION
All I have to do is provide my AWS credentials and put my volumes in the right places. With this setup, the two following backups are placed in my ptrvldz-backups bucket:
You can find s3-backup on GitHub and Docker Hub.