Initial restic docker setup

This commit is contained in:
Tobias Kaupat
2016-11-07 23:21:19 +01:00
parent 26a3f905ec
commit f181ceeca8
6 changed files with 77 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
FROM gliderlabs/alpine:3.3
MAINTAINER info@lobaro.com
RUN echo http://nl.alpinelinux.org/alpine/v3.4/community >> /etc/apk/repositories
RUN apk add --no-cache git go nfs-utils fuse
RUN git clone https://github.com/restic/restic \
&& cd restic \
&& go run build.go \
&& cp restic /usr/local/bin/
RUN apk del git go
RUN mkdir /mnt/restic
ENV RESTIC_REPOSITORY=/mnt/restic
ENV RESTIC_PASSWORD=""
ENV RESTIC_TAG=""
ENV NFS_TARGET=""
# By default backup every 6 hours
ENV BACKUP_CRON="* */6 * * *"
# /data is the dir where you have to put the data to be backed up
VOLUME /data
COPY backup.sh /bin/backup
RUN chmod +x /bin/backup
COPY entry.sh /entry.sh
RUN touch /var/log/cron.log
ENTRYPOINT ["/entry.sh"]
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
echo "Starting Backup"
restic backup /data --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> /var/log/cron.log
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
docker build --rm -t backup-test .
Executable
+20
View File
@@ -0,0 +1,20 @@
#!bin/sh
set -e
if [ -n "${NFS_TARGET}" ]; then
echo "Mounting NFS based on NFS_TARGET"
mount -o nolock -v ${NFS_TARGET} /mnt/restic
fi
if [ ! -f "$RESTIC_REPOSITORY/config" ]; then
echo "Restic repository does not exists. Running restic init."
restic init
fi
echo "Setup backup cron job with cron expression: ${BACKUP_CRON}"
echo "${BACKUP_CRON} /bin/backup >> /var/log/cron.log 2>&1" > /var/spool/cron/crontabs/root
# start the cron deamon
crond
tail -f /var/log/cron.log
Executable
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
echo "Removing old container names 'backup-test' if exists"
docker rm -f -v backup-test || true
echo "Start backup-test container. Backup of ~/test-data/ to repository ~/test-repo/ every minute"
docker run --privileged --name backup-test \
-e "RESTIC_PASSWORD=test" \
-e "RESTIC_TAG=test" \
-e "BACKUP_CRON=* * * * *" \
-v ~/test-data:/data \
-v ~/test-repo/:/mnt/restic \
-t backup-test
+1
View File
@@ -0,0 +1 @@
Just a file to test the backup