From 4a0a4b33e1290b4d6098e5d1a7e709cb96013988 Mon Sep 17 00:00:00 2001 From: Fabio Brito d'Araujo e Oliveira Date: Tue, 8 Sep 2020 14:55:06 +0200 Subject: [PATCH] Added option to specify target mount point --- bin/snap-sync | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/snap-sync b/bin/snap-sync index c2f0615..e604bac 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -112,6 +112,7 @@ Options: -r, --remote
ip address of a remote machine to backup to -s, --subvolid subvolume id of the mounted BTRFS subvolume to back up to -u, --UUID UUID of the mounted BTRFS subvolume to back up to + -m, --mountpoint Mount point to be used in case the volume is mounted multiple times See 'man snap-sync' for more details. EOF @@ -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 @@ -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 @@ -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 + if grep -q "$mountpoint_cmdline" <<< "$DETECTED_TARGETS" ;then + TARGETS=$mountpoint_cmdline + else + die "The provided mount point is not available" + fi +fi + declare -a TARGETS_ARRAY declare -a UUIDS_ARRAY declare -a SUBVOLIDS_ARRAY