THEAARBS tools - backup

Raw

#!/bin/bash
# Bound to Mod+Backspace

# # --- User-defined variables

# ServerHost should also be defined in ~/.ssh/config
# for key-authenticated sshfs connections to the
# backup repository
ServerHost="nas"

# NASPath should be the path to a writeable directory
# inside your backup repository
NASPath="/media/nas/backup/lenovo"

# NASMountRoot is the 'root' directory of your
# backup repository; this will be mounted to a local
# directory
NASMountRoot="../../sharedfolders"

# NASMountLocal is the local directory that is used
# to mount NASMountRoot
NASMountLocal="/media/nas"

# USBPath should be the path to a writeable directory
# on a mounted USB drive
USBPath="/run/media/theatomheart/xkey"

# Where should log files be stored
PathToLogs="/home/$USER/Logs/"

# # --- Functions
ClearExit() { clear && exit ;}
Say() { echo "$1" "$2" ; notify-send "$1" "$2" ;}
NoConnection() { Say "⛔ <b>$1</b> is not connected." ; ClearExit ;}
ConnectNAS() { sshfs $ServerHost:$NASMountRoot $NASMountLocal && Say "🔗 Connected to $ServerHost." ;}
BackupMenu() {
	choice=$(echo -e "USB\nNAS\nConfigure" | $mymenu "Backup Menu") || ClearExit
	clear
	case $choice in
		"USB")	path="$USBPath/$HOSTNAME" ;;
		"NAS")	path="$NASPath/$HOSTNAME" ;;
		"Configure")	openfile ~/.local/bin/backup
				ClearExit ;;
	esac ;}
BackupPath() {
	if [ ! -d $path ]; then
		case $choice in
			"USB")	NoConnection "$(basename $USBPath)" ;;
			"NAS")	ConnectNAS || NoConnection "$ServerHost" ;;
		esac
	fi
	if [ ! -d $path ]; then NoConnection "$ServerHost" ; fi ;}
GetConfirmation() {
	Confirm=$(echo -e "Yes\nNo" | $mymenu "Confirm: backup to $choice?") || ClearExit
	[[ $Confirm = "No" ]] && ClearExit
	clear ;}
RunBackup(){
	clear &&
	Say "⌛ Running backup" &&
	rsync -r -t -p -v --progress -u -s --delete \
		--exclude=$USER/VirtualBox* \
		--exclude=$USER/Mounts* \
		--exclude=$USER/.cache \
		--exclude=$USER/Podcasts \
		--exclude=$USER/Videos \
		--exclude=$USER/Downloads \
		--exclude=$USER/Music \
		$HOME $path &&
	Say "👍 Backup complete." &&
	mpv $HOME/.local/bin/notify.mp3 &>/dev/null ;}

# # --- Determine what to use for the menu
case $(tty) in
	*tty*)	runprefix="$TERMINAL -e"
		mymenu="dwmenu" ;;
	*)	runprefix=
		mymenu="slmenu -l 8 -i -p" ;;
esac

# # --- Simple steps
BackupMenu || ClearExit
BackupPath
GetConfirmation
RunBackup || Say "⛔ There was a problem running the backup."