Docker Volume Backup
Backup Docker container volumes to Filebase using Docker Volume Backup.
What is Docker Volume Backup?
Docker Volume Backup is a Docker image that can be used as a sidecar container to any existing Docker setup. This sidecar container can be configured for recurring or one time backups of Docker container volumes to any S3-compatible storage. It can also be configured to periodically delete old backups and send email notifications of backup failures.
Configure Recurring Backups In a docker-compose File
The following is a sample configuration for a docker-compose.yml file to add a backup service to your compose setup and mount the volumes you would like to see backed up:
version: '3'
services:
volume-consumer:
build:
context: ./my-container
volumes:
- data:/var/my-container
labels:
# This means the container will be stopped during backup to ensure backup integrity.
- docker-volume-backup.stop-during-backup=true
backup:
image: offen/docker-volume-backup:latest
restart: always
environment:
AWS_S3_BUCKET_NAME="filebase-bucket-name"
AWS_ACCESS_KEY_ID="Filebase-Access-Key"
AWS_SECRET_ACCESS_KEY="Filebase-Secret-Key"
AWS_ENDPOINT="s3.filebase.com"
AWS_ENDPOINT_PROTO="https"
volumes:
- data:/backup/my-app-backup:ro
# Mounting the Docker socket allows the script to stop and restart
# the container during backup. You can omit this if you don't want
# to stop the container
- /var/run/docker.sock:/var/run/docker.sock:ro
# If you mount a local directory or volume to `/archive` a local
# copy of the backup will be stored there. You can override the
# location inside of the container by setting `BACKUP_ARCHIVE`.
# You can omit this if you do not want to keep local backups.
- /path/to/local_backups:/archive
volumes:
data:env_file template:
Fill out the following environment variable template and save it as backup.env in the directory of your docker-compose file. If you use this method, you can replace the environment section in your docker-compose file with env-file: ./backup.env.
One Time Backups Using Docker CLI
To run a one time backup, mount the volume to be backed up into a container and run the backup command:
Or, you can pass the backup.env file as described above:
Restoring a volume from a backup
To restore a volume from a backup, use the following workflow:
Stop the container(s) that are using the volume.
Untar the backup you want to restore:
tar -C /tmp -xvf backup.tar.gzUsing a temporary container to mount the volume (called ‘data’ in this example) and copy over the backup.
docker run -d --name backup_restore -v data:/backup_restore alpinedocker cp /tmp/backup/data-backup backup_restore:/backup_restoredocker stop backup_restoredocker rm backup_restoreRestart the container(s) that are using the volume.
Depending on your setup, there may be additional steps needed.
Last updated
Was this helpful?