Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SNAZZER_SUBVOLS_EXCLUDE_FILE init code to function #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions snazzer
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,32 @@ fi
if [ -z "$SNAZZER_MEASUREMENTS_EXCLUDE_FILE" ]; then
SNAZZER_MEASUREMENTS_EXCLUDE_FILE=".snapshot_measurements.exclude"
fi
# Keep in sync with the POD!
if [ -z "$SNAZZER_SUBVOLS_EXCLUDE_FILE" ]; then
SNAZZER_SUBVOLS_EXCLUDE_FILE="/etc/snazzer/exclude.patterns"
fi

if ! $SUDO test -e "$SNAZZER_SUBVOLS_EXCLUDE_FILE"; then
MISSING_SUBVOLS_EXCL_FILE="$SNAZZER_SUBVOLS_EXCLUDE_FILE"
SNAZZER_SUBVOLS_EXCLUDE_FILE=$(mktemp)
cat <<HERE > "$SNAZZER_SUBVOLS_EXCLUDE_FILE"
init_subvols_exclude_file() {
# Keep in sync with the POD!
if [ -z "$SNAZZER_SUBVOLS_EXCLUDE_FILE" ]; then
SNAZZER_SUBVOLS_EXCLUDE_FILE="/etc/snazzer/exclude.patterns"
fi

if ! test -e "$SNAZZER_SUBVOLS_EXCLUDE_FILE"; then
MISSING_SUBVOLS_EXCL_FILE="$SNAZZER_SUBVOLS_EXCLUDE_FILE"
SNAZZER_SUBVOLS_EXCLUDE_FILE=$(mktemp)
cat <<HERE > "$SNAZZER_SUBVOLS_EXCLUDE_FILE"
var/cache
var/lib/docker/*
.snapshots
tmp
*backup*
*secret*
HERE
if [ "$DRY_RUN" = "1" ]; then printf "#"; fi
cat <<HERE >&2
if [ "$DRY_RUN" = "1" ]; then printf "#"; fi
cat <<HERE >&2
WARN: $MISSING_SUBVOLS_EXCL_FILE missing, defaulting to $SNAZZER_SUBVOLS_EXCLUDE_FILE:
HERE
printf " " >&2
sed ':a;N;$!ba;s/\n/, /g' "$SNAZZER_SUBVOLS_EXCLUDE_FILE" >&2
fi
printf " " >&2
sed ':a;N;$!ba;s/\n/, /g' "$SNAZZER_SUBVOLS_EXCLUDE_FILE" >&2
fi
}

# So, mountpoint(1) returns true if the path is a btrfs subvolume root, but we
# want to know if the path is a btrfs *filesystem* root. Hence the df/grep crazy
Expand Down Expand Up @@ -568,6 +571,7 @@ elif [ "$DO_FORCE" = "1" ] && [ "$DRY_RUN" = "1" ]; then
exit 1
elif [ "$DO_ALL" = "1" ]; then
assert_btrfs_tools
init_subvols_exclude_file
if [ -z "$1" ]; then
do_mountpoints
elif [ -n "$1" ] && [ -z "$2" ]; then
Expand All @@ -579,6 +583,7 @@ elif [ "$DO_ALL" = "1" ]; then
fi
else
assert_btrfs_tools
init_subvols_exclude_file
do_multiple "$DO_ACTION" "$@"
fi
if [ -n "$MISSING_SUBVOLS_EXCL_FILE" ]; then
Expand Down