mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-05-06 00:35:23 +00:00
Initial restic docker setup
This commit is contained in:
+31
@@ -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"]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Starting Backup"
|
||||
|
||||
restic backup /data --tag=${RESTIC_TAG?"Missing environment variable RESTIC_TAG"} >> /var/log/cron.log
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Just a file to test the backup
|
||||
Reference in New Issue
Block a user