Full Automated Container-Backup - Docker Style!
WARNING: This image is in ALPHA/POC-State! Don't rely your production backup on it! Also, since this Container could be EXTREMLY destructive, don't keep it running in background!
There are three requirements to run this container:
Since it's a lot to include in a single command, I will only show how to use this container in combination with docker-compose.
Clone git & build using docker/-compose:
git clone https://github.com/nold360/docker-borgbackup
cd docker-borgbackup
docker build .
Example:
version: "3"
services:
backup:
#build: .
image: nold360/docker-borgbackup
labels:
# Don't backup your backup...
one.gnu.docker.backup: "False"
environment:
#BORG_REPO MUST be set
BORG_REPO: "/backup"
# Those are default-values:
BORG_INIT_OPTIONS: "--encryption=none"
BORG_CREATE_OPTIONS: "-s --progress"
BORG_SKIP_VOLUME_SOURCES: "/proc,/sys,/var/run,/var/cache,/var/tmp"
BORG_BACKUP_ALL: "True"
BORG_BREAK_LOCK: "True"
volumes:
# needed for SSH-BORG_REPO:
- "./ssh:/ssh:ro"
# needed for local BORG_REPO:
- "./backup:/backup"
# needed for connecting the Docker-API
- "/var/run/docker.sock:/var/run/docker.sock"
# Include every volume-Path you might want to backup!
- "/srv:/srv"
- "/var/lib/docker:/var/lib/docker"
After setting up docker-compose.yml we can run our backup:
docker-compose run --rm backup
Path/Definition of the Borg-Repository. Can be a local path to a container volume (f.e. "/backup") or an SSH-Borg-Server (f.e. "borg@backup.domain:myRepo").
Note: When using SSH-Repo make sure to setup "/ssh" with ssh-key (and maybe known_hosts/config)!
Default: None (Must be configured!)
Options to pass to "borg init" when creating a new BORG_REPO Default: "--encryption=none"
Options to pass to "borg create" Default: "-s --progress"
List of Volume-Pathes to exclude globaly from backup. Default: "/proc,/sys,/var/run,/var/cache,/var/tmp"
Backup every container? Default: "True"
Forces "borg break-lock" before backing up; Helps recovering from aborted backups Warning: Can be ultimate destructive, when more then one borg-process is using the same BORG_REPO!
Default: "True"
Backup this container? Values: "True|False"
Only backup volumes specified in this comma-separated list: Example: "/data/foo,/bar"
Skip volumes specified in this comma-seperated list: Example: "/skip/me,/too"
Options/Parameters to pass to "borg create" Example: "-v --stats"
Included in this container is a Python-Wrapper script called just "backup". It implements the main backup/restore tasks.
docker-compose run backup --help
-------- Borg Docker Backup --------
usage: backup.py [-h] {restore,list,backup,info,borg} ...
Awesome Borg-Backup for Docker made simple!
positional arguments:
{restore,list,backup,info,borg}
Sub-Commands
restore Restore Container from Backup
list List archives / files in archive
backup Backup all / a single container
info Show infos about repo / archive
borg Run every board-command you like (not yet working)
optional arguments:
-h, --help show this help message and exit
The wrapper will collect all volumes mapped to a container and create a single backup archive for every container.
The archives will be named like this: my_container_name+2018-04-14_08:42
# docker-compose run backup backup -h
-------- Borg Docker Backup --------
usage: backup.py backup [-h] [container]
positional arguments:
container Name of the Container to backup (default: all)
Simply run the container without any arguments:
docker-compose run backup
docker-compose run backup my_container_name
Restoring a whole container is as simple as backing it up. You just need the name the the backup archive (see "list" subcommand).
docker-compose run backup restore my_container_name+2018-04-14_08:42
The wrapper will automatically:
# docker-compose run backup restore -h
-------- Borg Docker Backup --------
usage: backup.py restore [-h] archive
positional arguments:
archive Archive to Restore container from
optional arguments:
-h, --help show this help message and exit
docker-compose run backup list