Skip to content

Commit

Permalink
Find backup exlude files in home directores again
Browse files Browse the repository at this point in the history
  • Loading branch information
erikw committed Jan 17, 2022
1 parent d77c042 commit 424bb0c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion usr/local/sbin/restic_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 424bb0c

Please sign in to comment.