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

Added option to specify target mount point #85

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 18 additions & 2 deletions bin/snap-sync
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Options:
-r, --remote <address> ip address of a remote machine to backup to
-s, --subvolid <subvlid> subvolume id of the mounted BTRFS subvolume to back up to
-u, --UUID <UUID> UUID of the mounted BTRFS subvolume to back up to
-m, --mountpoint <path> Mount point to be used in case the volume is mounted multiple times

See 'man snap-sync' for more details.
EOF
Expand All @@ -138,6 +139,10 @@ while [[ $# -gt 0 ]]; do
subvolid_cmdline="$2"
shift 2
;;
-m|--mountpoint)
mountpoint_cmdline="$2"
shift 2
;;
-n|--noconfirm)
noconfirm="yes"
shift
Expand Down Expand Up @@ -166,6 +171,7 @@ done
description=${description:-"latest incremental backup"}
uuid_cmdline=${uuid_cmdline:-"none"}
subvolid_cmdline=${subvolid_cmdline:-"5"}
mountpoint_cmdline=${mountpoint_cmdline:-"none"}
noconfirm=${noconfirm:-"no"}

if [[ "$uuid_cmdline" != "none" ]]; then
Expand All @@ -191,13 +197,23 @@ fi

if [[ "$($ssh findmnt -n -v --target / -o FSTYPE)" == "btrfs" ]]; then
EXCLUDE_UUID=$($ssh findmnt -n -v -t btrfs --target / -o UUID)
TARGETS=$($ssh findmnt -n -v -t btrfs -o UUID,TARGET --list | grep -v $EXCLUDE_UUID | awk '{print $2}')
DETECTED_TARGETS=$($ssh findmnt -n -v -t btrfs -o UUID,TARGET --list | grep -v $EXCLUDE_UUID | awk '{print $2}')
UUIDS=$($ssh findmnt -n -v -t btrfs -o UUID,TARGET --list | grep -v $EXCLUDE_UUID | awk '{print $1}')
else
TARGETS=$($ssh findmnt -n -v -t btrfs -o TARGET --list)
DETECTED_TARGETS=$($ssh findmnt -n -v -t btrfs -o TARGET --list)
UUIDS=$($ssh findmnt -n -v -t btrfs -o UUID --list)
fi

if [[ "$mountpoint_cmdline" == "none" ]]; then
TARGETS=$DETECTED_TARGETS
else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indention is wrong here

if grep -q "$mountpoint_cmdline" <<< "$DETECTED_TARGETS" ;then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this single grep is satisfying enough. Or at least it could be improved. I did not test this, but what if detected targets contains /mnt/test but you specified /mnt via the command line? An exact match would be better here.

TARGETS=$mountpoint_cmdline
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt it make sense to escape the variable here when the path contains spaces?

else
die "The provided mount point is not available"
fi
fi

declare -a TARGETS_ARRAY
declare -a UUIDS_ARRAY
declare -a SUBVOLIDS_ARRAY
Expand Down