Giter VIP home page Giter VIP logo

restic's Introduction

docker-restic

Docker Pulls Docker layers Github Stars Github Stars Github Forks

Restic is a fantastic backup tool. To wrap this in a usefull and flexible docker container there is this repo.

Includes:

  • restic
  • cron (for scheduling)

Usage

Get latest image

You can run restic command very like this:

docker pull oursource/restic:latest
docker run --rm -e RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo" \
                -e AWS_ACCESS_KEY_ID="keyid" \
                -e AWS_SECRET_ACCESS_KEY="topsecret" \
                -e RESTIC_PASSWORD="some_good_hash" oursource/restic \
                -v /:/data
                restic snapshots

Create a docker-compose.yml

Adapt this file with your FQDN. Install docker-compose in the version 1.6 or higher.

restart: always ensures that the restic server container is automatically restarted by Docker in cases like a Docker service or host restart or container exit.

version: '2'

services:
  restic:
    restart: always
    image: oursource/restic:latest
    hostname: backup
    domainname: domain.com
    container_name: restic
    volumes:
      - /:/data
    environment:
      - RESTIC_BACKUP_OPTIONS="--exclude=/data/dir/*"
      - RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo"
      - AWS_ACCESS_KEY_ID="keyid"
      - AWS_SECRET_ACCESS_KEY="topsecret"
      - RESTIC_PASSWORD="some_good_hash"

Examples

Listed in these examples are also the defaults

to change the backup times:

For example you want to run the backup every day at 03:15.

version: '2'

services:
  restic:
    restart: always
    image: oursource/restic:latest
    hostname: backup
    domainname: domain.com
    container_name: restic
    volumes:
      - /:/data
    environment:
      - CRON_BACKUP_EXPRESSION="15   3  *   *   *"
      - RESTIC_BACKUP_OPTIONS="--exclude=/data/dir/*"
      - RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo"
      - AWS_ACCESS_KEY_ID="keyid"
      - AWS_SECRET_ACCESS_KEY="topsecret"
      - RESTIC_PASSWORD="some_good_hash"

to change the clean times and periods:

For example you want to run the backup every day at 00:00

version: '2'

services:
  restic:
    restart: always
    image: oursource/restic:latest
    hostname: backup
    domainname: domain.com
    container_name: restic
    volumes:
      - /:/data
    environment:
      - CRON_CLEANUP_EXPRESSION="0   0  *   *   *"
      - RESTIC_CLEANUP_KEEP_WEEKLY=5
      - RESTIC_CLEANUP_KEEP_MONTHLY=12
      - RESTIC_CLEANUP_KEEP_YEARLY=75
      - RESTIC_CLEANUP_OPTIONS="--prune"
      - RESTIC_BACKUP_OPTIONS="--exclude=/data/dir/*"
      - RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo"
      - AWS_ACCESS_KEY_ID="keyid"
      - AWS_SECRET_ACCESS_KEY="topsecret"
      - RESTIC_PASSWORD="some_good_hash"

Start the container

docker-compose up -d restic

You're done!


Commands to start with

A full explanation of the commands and options you can refer to the manual of restic

Initialize the repository

docker run --rm -e RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo" \
                -e AWS_ACCESS_KEY_ID="keyid" \
                -e AWS_SECRET_ACCESS_KEY="topsecret" \
                -e RESTIC_PASSWORD="some_good_hash" oursource/restic \
                -v /:/data
                restic init

List the snapshots

docker run --rm -e RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo" \
                -e AWS_ACCESS_KEY_ID="keyid" \
                -e AWS_SECRET_ACCESS_KEY="topsecret" \
                -e RESTIC_PASSWORD="some_good_hash" oursource/restic \
                -v /:/data
                restic snapshots

Restore a snapshot

docker run --rm -e RESTIC_REPOSITORY="s3:https://s3.amazonaws.com/some-repo" \
                -e AWS_ACCESS_KEY_ID="keyid" \
                -e AWS_SECRET_ACCESS_KEY="topsecret" \
                -e RESTIC_PASSWORD="some_good_hash" oursource/restic \
                -v /:/data
                restic restore _id_ --target /data/restore_location

Start a backup now when the container is running with the name restic

docker exec restic supervisorctl start restic_backup

Run any command in the container

docker exec -ti restic _command_

Environment variables

RESTIC_BACKUP_OPTIONS

  • "" => None set by default

RESTIC_CLEANUP_KEEP_DAILY

  • 7 => to keep 7 daily backups

RESTIC_CLEANUP_KEEP_WEEKLY

  • 5 => to keep 5 daily backups

RESTIC_CLEANUP_KEEP_MONTHLY

  • 12 => to keep 12 daily backups

RESTIC_CLEANUP_KEEP_YEARLY

  • 75 => to keep 75 daily backups

RESTIC_CLEANUP_OPTIONS

  • "--prune" => Clean the repository of old backups

CRON_BACKUP_EXPRESSION

  • *"15 3 * * " => Fire at 03:15 every day

CRON_CLEANUP_EXPRESSION

  • *"15 0 0 * " => Fire at 00:15 on the first day of every month

restic's People

Contributors

hamfactorial avatar johansmitsnl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

restic's Issues

Golang update

Restic 0.9.1 needs a newer version of Go to compile. This can be fixed by changing the first line of the Dockerfile to

FROM golang:1.10.3-alpine

I have pulled this repo and changed this locally and it works well. However, I don't have persmissions to push the change back.

Issues with quoting of Environment Variables

I've run into the following issue when using the given examples:

Fatal: parsing repository location failed: invalid backend
If the repo is in a local directory, you need to add a `local:` prefix

The problem seems to be the false quoting of the RESTIC_REPOSITORY environment variable:

environment:
  - RESTIC_REPOSITORY="b2:bucket:some/path"

For me the following version is working:

environment: 
  - "RESTIC_REPOSITORY=b2:bucket:some/path"

update: the same issue also applied to the CRON_*_EXPRESSION environment variables

my setup:
Docker version 18.09.0-ce, build 4d60db472b
docker-compose version 1.23.2, build unknown

I didn't find anything about quoting in the docker compose documentation, but I've found the following stackoverflow question:

https://stackoverflow.com/questions/41988809/docker-compose-how-to-escape-environment-variables

Initializing empty repo (new feature?)

I ran a new container with these variables: RESTIC_REPOSITORY, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, RESTIC_PASSWORD and no cmd set.

This means that (from what I understood), it will just run supervisord and eventually launch the backups.

The first time it tried to do the backup, it failed because restic couldn't find a valid repository.
I had to create another container with the same variables but with the cmd restic init (if I remember correctly).

So, first question: is this normal expected behaviour?
Second question: maybe we can make it into a feature to init the repo if there isn't one (before cron backup)?

restic reporting 128 TiB when backing up /var/lib/docker/aufs!!!!!

Everything has gone smoothly setting up this container to backup my Ubuntu system. I've created an exclude file to avoid wasting time with files and directories that I don't need backed up. The problem appeared when processing /var (specifically /var/lib/docker/aufs). restic is reporting that it needs to analyze up 128 TiB of data!!!!!!!
128 TiB

The actual data:

> du -hs  /var/lib/docker/aufs  
19G     /var/lib/docker/aufs
> find  /var/lib/docker/aufs | wc -l 
696063
> du -hs  /volume1/backups/restic-repo
37G     /volume1/backups/restic-repo

Needless to say my backup for this one subdirectory (which is already in my EXCLUDE list) has effectively made my backup almost 9000x slower (19 GB vs 128 TiB) than it should be!!!!

Help!

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.