From 424bb0c117285de5a3a22aee35f37544ec4a6fcf Mon Sep 17 00:00:00 2001 From: Erik Westrup Date: Mon, 17 Jan 2022 22:44:59 +0100 Subject: [PATCH] Find backup exlude files in home directores again --- usr/local/sbin/restic_backup.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/usr/local/sbin/restic_backup.sh b/usr/local/sbin/restic_backup.sh index b7c0cc1..f9bdbbb 100644 --- a/usr/local/sbin/restic_backup.sh +++ b/usr/local/sbin/restic_backup.sh @@ -20,13 +20,33 @@ exit_hook() { } trap exit_hook INT TERM -# Set up exclude files: global + path-specific ones. +# Set up exclude files: global + path-specific ones + home directoreis. +# NOTE that restic will fail the backup if not all listed --exclude-files exist. Thus we should only list them if they are really all available. +## Global backup configuration. exclusion_args="--exclude-file /etc/restic/backup_exclude" +## Self-contained backup files per backup path. E.g. having an USB disk at /mnt/media in BACKUP_PATHS, then it can have a /mnt/media/.backup_exclude for backup_path in ${BACKUP_PATHS[@]}; do if [ -f "$backup_path/.backup_exclude" ]; then exclusion_args+=" --exclude-file $backup_path/.backup_exclude" fi done +## Additonal service: if /home is being backed up, allow user specifci backup files in home directory or default $XDG_CONFIG_HOME path +backup_files_from_homedirs() { + local homeroot="$1" + local args= + if [[ $BACKUP_PATHS == *"$homeroot"* ]]; then + for homedir in $homeroot/*; do + excl_home="$homedir/.backup_exclude" + excl_xdg="$homedir/.config/restic/backup_exclude" + test -f $excl_home && args+=" --exclude-file $excl_home" + test -f $excl_xdg && args+=" --exclude-file $excl_xdg" + done + fi + echo $args +} +exclusion_args="$exclusion_args $(backup_files_from_homedirs /home)" +## And the same service of macOS users, having /Users instead of /home +exclusion_args="$exclusion_args $(backup_files_from_homedirs /Users)" # NOTE start all commands in background and wait for them to finish. # Reason: bash ignores any signals while child process is executing and thus the trap exit hook is not triggered.