christophetd / duplicacy-autobackup

:floppy_disk: Painless automated backups to multiple storage providers with Docker and duplicacy.
251 stars 42 forks source link
automated-backup azure backblaze-b2 backup docker duplicacy hubic s3

Duplicacy Autobackup

build status latest version

Duplicacy Autobackup is a Docker image to easily perform automated backups. It uses duplicacy under the hood, and therefore supports:

Usage

The following environment variables can be used to configure the backup strategy.

Additionally, the directory you want to backup must be mounted to /data on the container.

You need to provide credentials for the storage provider your of your choice using the following environment variables:

Environment variables marked with an asterix point to files. Those files must be mounted in the container so that they can be accessed from inside it.

If you want to execute an out of schedule backup, you can do so by running the script /app/backup.sh inside the container :

$ docker exec duplicacy-autobackup /app/duplicacy-autobackup.sh backup

Example

Backup /var/lib/mysql to the S3 bucket xtof-db-backups in the AWS region eu-west-1 every night at 2:00am, and encrypt them with the passphrase correct horse battery staple:

$ docker run -d --name duplicacy-autobackup \
    -v /var/lib/mysql:/data \
    -e BACKUP_NAME='prod-db-backups' \
    -e BACKUP_LOCATION='s3://eu-west-1@amazon.com/xtof-db-backups' \
    -e BACKUP_SCHEDULE='0 2 * * *' \
    -e BACKUP_ENCRYPTION_KEY='correct horse battery staple' \
    -e AWS_ACCESS_KEY_ID='AKIA...' \
    -e AWS_SECRET_KEY='...' \
    ghcr.io/christophetd/duplicacy-autobackup:v1.4.0

Viewing and restoring backups

Backups are useless if you don't make sure they work. This shows the procedure to list files, versions, and restore a duplicacy backup made using duplicacy-autobackup.

More: see Duplicacy's documentation.

Other options

You can have duplicacy-autobackup run a script before and after the backup process by mounting scripts on /scripts/pre-backup.sh and /scripts/post-backup.sh. For instance if you're backing up a MySQL database, this script can involve doing a mysqldump into /data/mydb.sql. If pre-backup.sh exits with a non-zero status code, the backup will not be performed until the next scheduled backup.

Use the following environment variables if you want to customize duplicacy's behavior.

Pruning old backups

Duplicacy offers an option to prune old backups. By default, duplicacy-autobackup does not perform any pruning. However, you can set the environment variables DUPLICACY_PRUNE_OPTIONS and PRUNE_SCHEDULE to perform automatic pruning. As an example, setting:

DUPLICACY_PRUNE_OPTIONS='-keep 0:360 -keep 30:180 -keep 7:30'
PRUNE_SCHEDULE='0 0 * * *'

Means that:

Choosing the Duplicacy version

When building the container, you can choose the Duplicacy version that will be used in the container image. The build argument DUPLICACY_VERSION is available for that purpose, e.g.:

docker build --build-arg DUPLICACY_VERSION=2.1.0 -t christophetd/duplicacy-autobackup .

Disclaimer

This project uses Duplicacy, which is free for personal use but requires purchasing a licence for non-trial commercial use. See the detailed terms here.

Contact

Feel free to open an issue for any suggestion or bug. You can also tweet @christophetd.