From 7b5e4aabd5c4946d1d0e7772693d02652fb14bc8 Mon Sep 17 00:00:00 2001 From: Wes Barnett Date: Fri, 29 Jan 2021 22:34:31 -0500 Subject: [PATCH 1/2] Add -m option to manually specify mount point Fixes #71 --- bin/snap-sync | 33 +++++++++++++++++++++++++-------- man8/snap-sync.8 | 11 ++++++++++- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/bin/snap-sync b/bin/snap-sync index 91a5457..344a865 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -92,6 +92,7 @@ Options: -n, --noconfirm do not ask for confirmation -k, --keepold keep old incremental snapshots instead of deleting them after backup is performed + -m, --mountpoint optionally specify where subvolume is mounted if mounted in multiple locations -p, --port remote port; wsed with '--remote'. -q, --quiet do not send notifications; instead print them. -r, --remote
ip address of a remote machine to backup to @@ -105,6 +106,7 @@ EOF ssh="" sudo=0 +mount_cmdline="" while [[ $# -gt 0 ]]; do key="$1" case $key in @@ -124,6 +126,10 @@ while [[ $# -gt 0 ]]; do subvolid_cmdline="$2" shift 2 ;; + -m|--mountpoint) + mount_cmdline="$2" + shift 2 + ;; -k|--keepold) keep="yes" shift @@ -237,14 +243,25 @@ done i=0 disk=-1 disk_count=0 -for x in $UUIDS; do - UUIDS_ARRAY[$i]=$x - if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" ]]; then - disk=$i - disk_count=$(($disk_count+1)) - fi - i=$((i+1)) -done +if [[ -z "$mount_cmdline" ]]; then + for x in $UUIDS; do + UUIDS_ARRAY[$i]=$x + if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" ]]; then + disk=$i + disk_count=$(($disk_count+1)) + fi + i=$((i+1)) + done +else + for x in $UUIDS; do + UUIDS_ARRAY[$i]=$x + if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" && ${TARGETS_ARRAY[$((i))]} == "$mount_cmdline"]]; then + disk=$i + disk_count=$(($disk_count+1)) + fi + i=$((i+1)) + done +fi if [[ "${#UUIDS_ARRAY[$@]}" -eq 0 ]]; then die "No external btrfs subvolumes found to backup to. Run '$name -h' for more options." diff --git a/man8/snap-sync.8 b/man8/snap-sync.8 index 4018891..6f67de1 100644 --- a/man8/snap-sync.8 +++ b/man8/snap-sync.8 @@ -12,6 +12,7 @@ snap-sync \- send incremental btrfs snapshots, keeping track of them with snappe [\fB-p\fR \fIport\fR] [\fB--sudo\fR] [\fB-s\fR \fIsubvolid\fR] +[\fB-m\fR \fImountpoint\fR] [\fB-u\fR \fIUUID\fR] [\fB-k\fR] [\fB-q\fR] @@ -110,7 +111,15 @@ Specify the subvolume id of the mounted BTRFS subvolume to back up to. Defaults \fB\-u, \-\-UUID\fR \fIUUID\fR .RS 4 Specify the UUID of the mounted BTRFS subvolume to back up to. Otherwise will prompt. -If multiple mount points are found with the same UUID and subvolid, will prompt user. +If multiple mount points are found with the same UUID and subvolid, will prompt user, +or user can specify mount point manually with \fB-m\fR. +.RE +.PP + +\fB\-m, \-\-mountpoint\fR \fImount point\fR +.RS 4 +Specify the mount point of the disk to back up to. Useful if multiple mount points +are used for the same disk. .RE .PP From 45dcb51f556cc37d30d7086ac416cea6c230a898 Mon Sep 17 00:00:00 2001 From: Wes Barnett Date: Fri, 29 Jan 2021 22:49:02 -0500 Subject: [PATCH 2/2] Fix typo, expand error message --- bin/snap-sync | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/snap-sync b/bin/snap-sync index 344a865..1bb472e 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -255,7 +255,7 @@ if [[ -z "$mount_cmdline" ]]; then else for x in $UUIDS; do UUIDS_ARRAY[$i]=$x - if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" && ${TARGETS_ARRAY[$((i))]} == "$mount_cmdline"]]; then + if [[ "$x" == "$uuid_cmdline" && ${SUBVOLIDS_ARRAY[$((i))]} == "$subvolid_cmdline" && ${TARGETS_ARRAY[$((i))]} == "$mount_cmdline" ]]; then disk=$i disk_count=$(($disk_count+1)) fi @@ -274,7 +274,7 @@ fi if [[ "$disk" == -1 ]]; then if [[ "$disk_count" == 0 && "$uuid_cmdline" != "none" ]]; then - error "A device with UUID $uuid_cmdline and subvolid $subvolid_cmdline was not found to be mounted, or it is not a BTRFS device." + error "A device with UUID $uuid_cmdline and subvolid $subvolid_cmdline was not found to be mounted, or it is not a BTRFS device, or you specified an invalid mount point" fi if [[ -z $ssh ]]; then printf "Select a mounted BTRFS device on your local machine to backup to.\nFor more options, exit and run '$name -h'.\n"