Skip to content

Instantly share code, notes, and snippets.

@mhluska
Last active December 17, 2015 18:18
Show Gist options
  • Save mhluska/5651803 to your computer and use it in GitHub Desktop.
Save mhluska/5651803 to your computer and use it in GitHub Desktop.
Used with udev to sync a backup drive.
#!/bin/bash
drive_name="${1}"
if [ -z "${drive_name}" ]; then
exit 1
fi
USERNAME='username'
SOURCE_DIR="/home/${USERNAME}/Backup"
function notify() {
su "${USERNAME}" -c "DISPLAY=:0.0 /usr/bin/notify-send '${1}'"
}
# Wait for Ubuntu to auto-mount the drive.
drive_dir=
while [ -z "${drive_dir}" ]; do
sleep 2
drive_dir="$(grep "${drive_name}" /etc/mtab | awk '{print $2}')"
done
notify "Syncing ${drive_dir}"
HOME=/root unison "${SOURCE_DIR}" "${drive_dir}" -batch -prefer newer -times=true -perms 0
notify "Finished syncing ${drive_dir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment