Toastie 4 years ago
parent
commit
a6adabf84b

+ 6 - 0
restic/.env.template

@@ -0,0 +1,6 @@
+BACKUP_SOURCE=/home
+RESTIC_FORGET_ARGS=--keep-weekly 2 --prune
+AWS_ACCESS_KEY_ID=example-TwelveChar
+AWS_SECRET_ACCESS_KEY=30RandomAlphaNumericCharacters
+RESTIC_PASSWORD=AnotherSetOf30RandomCharacters
+RESTIC_REPOSITORY=s3:https://example.ulm-store.de/mybackup

+ 1 - 0
restic/.gitignore

@@ -0,0 +1 @@
+.env

+ 23 - 0
restic/README.md

@@ -0,0 +1,23 @@
+## Restic 
+
+This [`docker-compose.yml`](./docker-compose.yml) file runs Restic backup as per [`crontab.txt`](data/restic/crontab.txt) with parameters set in  [`.env`](.env.template) using the [restic/restic](https://hub.docker.com/r/restic/restic/).
+
+#### Setup your config
+```
+cp .env.template .env
+vi .env
+```
+
+#### Adjust the timing
+```
+vi ./data/restic/crontab.txt
+```
+
+#### Run the container
+```
+docker-compose up -d
+docker logs restic -f
+```
+
+#### References
+- Restic docu: https://restic.readthedocs.io/en/stable/index.html

+ 2 - 0
restic/data/restic/crontab.txt

@@ -0,0 +1,2 @@
+0 3 * * * /etc/restic/run.sh 0 2>&1
+#*/1 * * * * /root/restic/run.sh 0 2>&1

+ 7 - 0
restic/data/restic/entry.sh

@@ -0,0 +1,7 @@
+#!/bin/sh -x
+
+# Import cron file
+/usr/bin/crontab /root/restic/crontab.txt
+
+# Start cron
+/usr/sbin/crond -f -L /dev/stdout

+ 11 - 0
restic/data/restic/run.sh

@@ -0,0 +1,11 @@
+#!/bin/sh -xe
+
+# Init restic repository if neccessary
+restic snapshots &>/dev/null || restic init
+
+# Run backup job, using parameters from AWS_ACCESS_KEY_ID,
+# AWS_SECRET_ACCESS_KEY, RESTIC_PASSWORD, RESTIC_REPOSITORY
+restic backup /mnt/source
+
+# Cleanup old backups
+restic forget ${RESTIC_FORGET_ARGS}

+ 13 - 0
restic/docker-compose.yml

@@ -0,0 +1,13 @@
+version: '2' 
+services:
+  restic:
+    image: restic/restic
+    container_name: restic
+    hostname: restic
+    restart: on-failure:3
+    volumes:
+      - ${BACKUP_SOURCE}:/mnt/source:ro 
+      - ./data/restic:/root/restic:ro
+    env_file: .env 
+    #entrypoint: /bin/sh
+    entrypoint: /root/restic/entry.sh