Skip to content

Instantly share code, notes, and snippets.

@tpikonen
Created January 10, 2017 17:17
Show Gist options
  • Save tpikonen/c7739ea08c3862c64ee71abc02e1ad56 to your computer and use it in GitHub Desktop.
Save tpikonen/c7739ea08c3862c64ee71abc02e1ad56 to your computer and use it in GitHub Desktop.
Mount a remote bup repository to a local directory with sshfs and 'bup fuse'. A convenience script to save on manual mount point creation etc.
#!/bin/sh
# Mount a remote bup repository to a local directory with sshfs
# and 'bup fuse'.
# A convenience script to save on manual mount point creation etc.
#
# Usage:
# bup-rfuse <server:remotedir/repo-bup> <mountpoint>
# (mountpoint is created if it does not exist)
# or just with the defaults (see below)
# bup-rfuse
# Defaults
REMOTE="server:/dir/repo-bup"
MOUNTPOINT="$HOME/bfuse"
# die $EXITCODE $MESSAGE
# Print and log a message and exit
die () {
echo "$2"
echo "Exiting with code $1"
exit $1
}
# clean_up
# Unmount bup fuse and remove sshfs mount point. Called after ctrl-c.
clean_up () {
echo "CLEANUP!"
fusermount -u $MOUNTPOINT
# fusermount -u $SSHMOUNT
rmdir $SSHMOUNT
exit
}
if [ "$#" = "2" ] ; then
REMOTE="$1"
MOUNTPOINT="$2"
elif [ "$#" = "0" ] ; then
true
else
die 10 "Usage: $0 <server:remotedir/repo-bup> <mountpoint>"
fi
[ ! -d $MOUNTPOINT ] && (echo "Creating $MOUNTPOINT" ; mkdir $MOUNTPOINT )
[ -n "$(ls -A $MOUNTPOINT)" ] && die 1 "Mountpoint $MOUNTPOINT not empty"
SSHMOUNT=$(mktemp --tmpdir -d buprfuse-XXXX)
trap clean_up 1 2 15 #SIGHUP SIGINT SIGTERM
SCMD="sshfs $REMOTE $SSHMOUNT"
echo "Running $SCMD"
$SCMD
[ ! $? -eq 0 ] && die 2 "Could not sshfs to $REMOTE"
BCMD="bup -d $SSHMOUNT fuse -f $MOUNTPOINT"
echo "Running $BCMD"
echo "Press Ctrl-C to stop"
$BCMD &
while true; do
sleep 1h
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment