# Simple rSync script to sync certain data between my desktop and laptop... # Hooman Baradaran # NOTES: # Don't forget to change variable REMOTE with remove IP or hostname # Since this script is meant to sync two computers and will be called # regularly between the two computers, remote name and directory # names are stored in the script rather than command line args. # Since rsync is called a few times, password should be skipped # For example, I use RSA keys with ssh. # Enjoy! VERBOSE="-v" # -v for verbose mode, empty for quiet mode RSHELL="-e ssh" # -e or blank to skip RSYNC="rsync -a $VERBOSE $RSHELL --delete" # IP address or host names, LOCAL can be blank for local host LOCAL="" # LEAVE BLANK FOR LOCAL, OR ADD COLUMNS e.g."local:" REMOTE="192.168.0.5" # CHANGE WITH REMOTE IP, DON'T ADD COLUMNS TO THIS! # Characters to select the sync mode: LOCAL_TO_REMOTE="upload" REMOTE_TO_LOCAL="download" if [ tt$1 = "tt-d" ]; then REMOTE=$2 MODE=$3 else MODE=$1 fi if [ $MODE == $LOCAL_TO_REMOTE ]; then SRC=$LOCAL DEST=${REMOTE}: elif [ $MODE == $REMOTE_TO_LOCAL ]; then SRC=${REMOTE}: DEST=$LOCAL else echo "usage: [-d destination] $0 " echo " \"${LOCAL_TO_REMOTE}\" to sync from this host to remote machine." echo " \"${REMOTE_TO_LOCAL}\" to sync from remote machine to this host." exit 1 fi # FILES & DIRECTORIES TO SYNC: # If SRC and DEST are the same add them in the same format below: # For new rsync versions with --files-from support (fast) echo " ${HOME}/Mail/ ${HOME}/Documents/ ${HOME}/public_html/ " || $RSYNC --files-from=- ${SRC}$FILE ${DEST}$FILE # You can use a separate file for the list (see rsync man) # For older rsync versions (slow) for FILE in\ "${HOME}/Mail/"\ "${HOME}/Documents/"\ "${HOME}/public_html/" do $RSYNC ${SRC}$FILE ${DEST}$FILE done # To sync home directories: # $RSYNC ${SRC}${HOME} ${DEST}${HOME}