#!/bin/sh
set -eu

usage() {
    echo "$(basename "$0") [-c]"
}

if [ "$#" -eq 0 ]
then
    ssh -t host01.shore.co.il -o \
        "RemoteCommand tmux new-session -As backup sudo sh -c 'mount /dev/sdb1 /mnt && offsite-backup /mnt && umount /mnt'"
elif [ "$1" = '-c' ]
then
    if ssh host01.shore.co.il tmux has-session -t backup 2>/dev/null
    then
        echo 'Backup is still running.'
    else
        echo 'Backup has finished.'
        exit 1
    fi
else
    usage
    exit 1
fi
