Skip to main content

Backup and Restore

Persistent data generated and consumed by Docker containers are stored on Docker volumes. You can containerize stateful workloads because data stored in a volume is available even after your containers have stopped running. However, disasters like disk failures, accidental deletions, or malicious attacks can still happen to volumes. For the safe side, you should periodically back up your volumes so that you can restore them in the case of data loss or corruption.

There are multiple ways to backup the docker volume, but the most common way is to use a temporary container that mounts the volume and builds an archive of its contents. Through offen/docker-volume-backup Docker image this process has been automated. The offen/docker-volume-backup Docker image can be used as a lightweight (below 15MB) companion container to an existing Docker setup. It handles recurring or one-off backups of Docker volumes to a local directory, any S3, WebDAV, Azure Blob Storage, Dropbox or SSH compatible storage (or any combination thereof) and rotates away old backups if configured. It also supports encrypting your backups using GPG and sending notifications for (failed) backup runs. Below is a snippet from the BSTS stack compose file

 backup:
container_name: "app-backup"
image: offen/docker-volume-backup:latest
restart: always
env_file: ./backup.env
volumes:
- web_data:/backup/web_data:ro
- db_data:/backup/db_data:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./backups/recurrent:/archive
networks:
- net

web_data is the website volume to be backed up db_dat is the database volume to be backed up The configuration of the offen/docker-volume-backup service is provided in backup.env

########### BACKUP SCHEDULE
BACKUP_CRON_EXPRESSION="42,47,52 * * * *"
BACKUP_RETENTION_DAYS="7"
BACKUP_FROM_SNAPSHOT="false"

NOTIFICATION_URLS=smtp://everardo.anderson47@ethereal.email:ZmPpFFF9TDYc7m6CtB@smtp.ethereal.email:587/?fromAddress=admin@podctl.xyz&toAddresses=supervisor@podctl.xyz
NOTIFICATION_LEVEL="info"