Skip to content

Instantly share code, notes, and snippets.

@SteveRyherd
Created February 27, 2013 01:35
Show Gist options
  • Save SteveRyherd/5044146 to your computer and use it in GitHub Desktop.
Save SteveRyherd/5044146 to your computer and use it in GitHub Desktop.
Bash script for synchronizing data from a directory to a WDTV or other external drive. -- NOTE: This script is asynchronous unlike the imgur drop script.
#!/bin/bash
NET_DIR="//stevestv.local/portable"
TARGET_DIR="/media/wdtv"
SOURCE_DIR="/srv/wdtv/" #Include the trailing slash
# Exit upon errors
set -e
# Check if directory exists
if [ ! -d "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
# Check if mountpoint exists there
if ! mountpoint -q "$TARGET_DIR" ; then
echo "Mounting WDTV ... "
sudo mount -t cifs "$NET_DIR" "$TARGET_DIR" -o guest,rw,uid=1000,gid=1000,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777
fi
# Perform the syncronization
# Recursive, verbose, compress, preserve permissions, times, groups, etc
echo "Syncing Data ..."
rsync -rvzptgoD --copy-links --copy-dirlinks "$SOURCE_DIR" "$TARGET_DIR"
echo "Syncronization Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment