From 71797bdd07cf877339b88fc0a7c41436960a1356 Mon Sep 17 00:00:00 2001 From: Murdock Grewar Date: Sat, 4 Dec 2021 20:43:41 +1100 Subject: [PATCH 1/2] Bugfix: allow backing up of read-only mount /data This commit allows the user to backup mounts at /data which are mounted as read-only. There is a slight break to previous behaviour which may affect some users: symlinks inside /data which point to absolute paths *used* to be followed, and their contents included in the backup. This is no longer the case. --- Dockerfile | 3 +++ dispose-symlinks.sh | 7 +++++++ duplicacy-autobackup.sh | 2 +- entrypoint.sh | 4 ++++ make-symlinks.sh | 8 ++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 dispose-symlinks.sh create mode 100755 make-symlinks.sh diff --git a/Dockerfile b/Dockerfile index 84bc8ec..a555e54 100755 --- a/Dockerfile +++ b/Dockerfile @@ -48,5 +48,8 @@ WORKDIR /app ADD *.sh ./ RUN chmod +x *.sh +RUN mkdir /wd +WORKDIR /wd + VOLUME ["/data"] ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/dispose-symlinks.sh b/dispose-symlinks.sh new file mode 100755 index 0000000..d479d9c --- /dev/null +++ b/dispose-symlinks.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# Delete all files in /wd/ except for .duplicacy +# This needs rm -f because the symlinks created previously may inherit read-only permissions. +cd / +find /wd/ -mindepth 1 -maxdepth 1 -not -path /wd/.duplicacy -exec rm -f {} \; +cd - > /dev/null diff --git a/duplicacy-autobackup.sh b/duplicacy-autobackup.sh index 3dd2c78..daada9e 100755 --- a/duplicacy-autobackup.sh +++ b/duplicacy-autobackup.sh @@ -3,7 +3,7 @@ PRE_BACKUP_SCRIPT="/scripts/pre-backup.sh" POST_BACKUP_SCRIPT="/scripts/post-backup.sh" -cd /data +cd /wd do_init() { : ${BACKUP_NAME:?'Missing BACKUP_NAME'} diff --git a/entrypoint.sh b/entrypoint.sh index f67bd1c..4f81ee4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,11 +2,15 @@ echo "$BACKUP_SCHEDULE /app/duplicacy-autobackup.sh backup" > /var/spool/cron/crontabs/root echo "$PRUNE_SCHEDULE /app/duplicacy-autobackup.sh prune" >> /var/spool/cron/crontabs/root +cd /wd + /app/duplicacy-autobackup.sh init if [[ $BACKUP_IMMEDIATLY == "yes" ]] || [[ $BACKUP_IMMEDIATELY == "yes" ]]; then # two spellings for retro-compatibility echo "Running a backup right now" + /app/make-symlinks.sh # Create symlinks in /wd/ to items in /data/ /app/duplicacy-autobackup.sh backup + /app/dispose-symlinks.sh fi crond -l 8 -f diff --git a/make-symlinks.sh b/make-symlinks.sh new file mode 100755 index 0000000..7be4e7c --- /dev/null +++ b/make-symlinks.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Duplicacy will follow symlinks at the top level of the working directory. +# (Note: these symlinks must point to absolute paths) +# For each item in /data, create a symlink (of the same name) to its _absolute path_ in /data/ +cd / +find /data/ -mindepth 1 -maxdepth 1 -exec sh -c 'ln -s "$0" "/wd/$(basename "$0")"' {} \; +cd - > /dev/null From a2473a36aff9e00928cd4d7b09cd682e67617be0 Mon Sep 17 00:00:00 2001 From: Murdock Grewar Date: Sun, 12 Dec 2021 20:54:39 +1100 Subject: [PATCH 2/2] Critical bugfix: backups were not updating after an 'immediate' option startup backup. --- duplicacy-autobackup.sh | 2 ++ entrypoint.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/duplicacy-autobackup.sh b/duplicacy-autobackup.sh index 0c1050f..b8c4aa2 100755 --- a/duplicacy-autobackup.sh +++ b/duplicacy-autobackup.sh @@ -34,7 +34,9 @@ do_backup() { return fi + /app/make-symlinks.sh # Create symlinks in /wd/ to items in /data/ duplicacy backup $DUPLICACY_BACKUP_OPTIONS + /app/dispose-symlinks.sh if [[ -f $POST_BACKUP_SCRIPT ]]; then echo "Running post-backup script" diff --git a/entrypoint.sh b/entrypoint.sh index 4f81ee4..9a57136 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,9 +8,7 @@ cd /wd if [[ $BACKUP_IMMEDIATLY == "yes" ]] || [[ $BACKUP_IMMEDIATELY == "yes" ]]; then # two spellings for retro-compatibility echo "Running a backup right now" - /app/make-symlinks.sh # Create symlinks in /wd/ to items in /data/ /app/duplicacy-autobackup.sh backup - /app/dispose-symlinks.sh fi crond -l 8 -f