Code Monkey home page Code Monkey logo

restic-backup-docker's Introduction

Restic Backup Docker Container

A docker container to automate restic backups

This container runs restic backups in regular intervals.

  • Easy setup and maintanance
  • Support for different targets (currently: Local, NFS, SFTP)
  • Support restic mount inside the container to browse the backup files

Test the container

Clone this repository

git clone https://github.com/Mantha32/restic-backup-docker.git
cd restic-backup-docker

Make your B2 credential on this file: b2-account-id, b2-account-key and the bucket name.

b2_env.sh

Make your B2 password on this file

b2_passwd.sh

Build the container. The container is named backup-test

./build.sh

Run the container.

./run.sh

This will run the container backup-test with the name backup-test. Existing containers with that names are completly removed automatically.

The container will backup ~/test-data to a repository with password test at ~/test-repo every minute. The repository is initialized automatically by the container.

To enter your container execute

docker exec -ti backup-test /bin/sh

backup

Do the backup manually. Otherwise the backup run each time that define in the run.sh script

backup

Now you can use restic as documented, e.g. try to run restic snapshots to list all your snapshots.

restore

Run the restore command with the snapshot ID.

restore 9a83a611

Logfiles

Logfiles are inside the container. If needed you can create volumes for them.

docker logs

Shows /var/log/cron.log

Additionally you can see the the full log, including restic output, of the last execution in /var/log/backup-last.log. When the backup fails the log is copied to /var/log/restic-error-last.log.

Customize the Container

The container is setup by setting environment variables and volumes.

Environment variables

  • RESTIC_REPOSITORY - the location of the restic repository. Default /mnt/restic
  • RESTIC_PASSWORD - the password for the restic repository. Will also be used for restic init during first start when the repository is not initialized.
  • RESTIC_TAG - Optional. To tag the images created by the container.
  • NFS_TARGET - Optional. If set the given NFS is mounted, i.e. mount -o nolock -v ${NFS_TARGET} /mnt/restic. RESTIC_REPOSITORY must remain it's default value!
  • BACKUP_CRON - A cron expression to run the backup. Note: cron daemon uses UTC time zone. Default: 0 */6 * * * aka every 6 hours.
  • RESTIC_FORGET_ARGS - Optional. Only if specified restic forget is run with the given arguments after each backup. Example value: -e "RESTIC_FORGET_ARGS=--prune --keep-last 10 --keep-hourly 24 --keep-daily 7 --keep-weekly 52 --keep-monthly 120 --keep-yearly 100"
  • RESTIC_JOB_ARGS - Optional. Allows to specify extra arguments to the back up job such as limiting bandwith with --limit-upload or excluding file masks with --exclude.

Volumes

  • /data - This is the data that gets backed up. Just mount it to wherever you want.

Set the hostname

Since restic saves the hostname with each snapshot and the hostname of a docker container is it's id you might want to customize this by setting the hostname of the container to another value.

Either by setting the environment variable HOSTNAME or with --hostname in the network settings

Backup to SFTP

Since restic needs a password less login to the SFTP server make sure you can do sftp user@host from inside the container. If you can do so from your host system, the easiest way is to just mount your .ssh folder conaining the authorized cert into the container by specifying -v ~/.ssh:/root/.ssh as argument for docker run.

Now you can simply specify the restic repository to be an SFTP repository.

-e "RESTIC_REPOSITORY=sftp:user@host:/tmp/backup"

Changelog

Versioning follows Semantic versioning

! Breaking changes

:latest

  • ! --prune must be passed to RESTIC_FORGET_ARGS to execute prune after forget.
  • Switch to base Docker container to golang:1.7-alpine to support latest restic build.

:v1.0

  • First stable version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.