Added backup scripts

This commit is contained in:
lanxu 2020-06-03 16:51:40 +03:00
parent 4160f106b3
commit 3342da0c94
4 changed files with 43 additions and 0 deletions

18
backup/Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM alpine:3.10
# install dependencies
RUN apk add restic
RUN apk add curl
# install rclone
RUN curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip &&\
unzip rclone-current-linux-amd64.zip &&\
cd rclone-*-linux-amd64 &&\
cp rclone /usr/bin/ &&\
chown root:root /usr/bin/rclone &&\
chmod 755 /usr/bin/rclone
COPY restic_backup.sh /usr/bin/
RUN chmod +x /usr/bin/restic_backup.sh
ENTRYPOINT ["restic_backup.sh"]

9
backup/backup.env Normal file
View File

@ -0,0 +1,9 @@
RETENTION_DAYS=7
RETENTION_WEEKS=4
RETENTION_MONTHS=6
RETENTION_YEARS=3
BACKUP_PATHS=/mnt/backup/
RESTIC_REPOSITORY=rclone:hubic:TestBackup
RESTIC_PASSWORD=testbackup
RESTIC_PARAMS=--exclude-file /mnt/restic-exclude
RCLONE_CONFIG=/mnt/rclone.conf

5
backup/restic_backup.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
restic snapshots > /dev/null || restic init || exit 0
restic backup $RESTIC_PARAMS $BACKUP_PATHS || exit 0
restic forget --verbose --group-by "paths,tags" --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS

11
backup/run_backup.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
docker build -t backup . --network=host
docker run \
--env-file=./backup.env \
-v /tmp/test/:/mnt/backup/ \
-v /tmp/test/restic-exclude.txt:/mnt/restic-exclude \
-v /tmp/test/rclone.conf:/mnt/rclone.conf \
-v /tmp/logs/:/mnt/logs/ \
--network=host \
backup