Skip to content

Commit

Permalink
Merge pull request #67 from greezybacon/feature/mountpoint-check
Browse files Browse the repository at this point in the history
Add optional check for remote mounted mountpoint(s)
  • Loading branch information
greezybacon authored Aug 9, 2018
2 parents 2128a35 + a91c569 commit aa44275
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bin/bitpocket
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SLOW_SYNC_FILE="$TMP_DIR/slow"
RSYNC_RSH="ssh"
REMOTE_BACKUPS=false
BACKUPS=true
REMOTE_MOUNTPOINT=false

# Default command-line options and such
COMMANDS=()
Expand Down Expand Up @@ -134,6 +135,13 @@ REMOTE_BACKUPS=false
# SLOW_SYNC_TIME=10
# SLOW_SYNC_START_CMD="notify-send 'BitPocket sync in progress...'"
# SLOW_SYNC_STOP_CMD="notify-send 'BitPocket sync finished'"
## Indicate a remote mount point. If this is set and the mountpoint is not
## mounted, then the bitpocket sync will abort. This addresses situations where
## a sync target appears empty because it is not mounted. Such a sync might
## result in all local or remote data disappearing. Give the expected
## mountpoint of the local and/or remote target.
# REMOTE_MOUNTPOINT=/
EOF

echo "Initialized bitpocket directory at `pwd`"
Expand Down Expand Up @@ -340,6 +348,7 @@ function analyse {
# Do the actual synchronization
function sync {
assert_dotdir
assert_mountpoints
acquire_lock
acquire_remote_lock

Expand Down Expand Up @@ -515,6 +524,24 @@ function assert_dotdir {
mkdir -p "$STATE_DIR"
}

function assert_mountpoints {
if [[ ${REMOTE_MOUNTPOINT} != false ]]
then
# Sanity check -- ensure mountpoint is a parent of local target
if [[ "${REMOTE_PATH:0:${#REMOTE_MOUNTPOINT}}" != "${REMOTE_MOUNTPOINT}" ]]
then
echo -e "${YELLOW}warning: Remote mount point is not a parent of '${REMOTE_PATH}'${CLEAR}"
fi

$REMOTE_RUNNER "mount | grep -E '\s${REMOTE_MOUNTPOINT}\s'" &> /dev/null
if [[ $? != 0 ]]
then
echo -e "${RED}fatal: Remote sync target is not mounted${CLEAR}"
exit 4
fi
fi
}

function cleanup {
release_lock
release_remote_lock
Expand Down

0 comments on commit aa44275

Please sign in to comment.