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

Add option to specify mount point #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 26 additions & 9 deletions bin/snap-sync
Original file line number Diff line number Diff line change
Expand Up @@ -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 <port> remote port; wsed with '--remote'.
-q, --quiet do not send notifications; instead print them.
-r, --remote <address> ip address of a remote machine to backup to
Expand All @@ -105,6 +106,7 @@ EOF

ssh=""
sudo=0
mount_cmdline=""
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would do something like:

if [[ -n "$mount_cmdline" && ${TARGETS_ARRAY[$((i))]} != "$mount_cmdline" ]]; then
    continue
fi

This should make the code smaller, but I did not test it.

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."
Expand All @@ -257,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"
Expand Down
11 changes: 10 additions & 1 deletion man8/snap-sync.8
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

Expand Down