#!/bin/bash
# This script will recurse through the directories listed under ~/Documents/code
# and back each of them up on the remote computer at the desired location.

# remote location
declare REMOTE_HOST
REMOTE_HOST="username@hostname:~/myBackup/"

# local directory to backup
declare LOCAL_DIR
LOCAL_DIR="~/Documents/code/"

# ignore list
declare IGNORE_LIST
IGNORE_LIST="nobackup"

# ssh user name
declare SSH_USERNAME
SSH_USERNAME="myUsername"

# Get file listing..
declare DIR_LIST
declare DIR_LISTING="$(eval ls $LOCAL_DIR | grep -v $IGNORE_LIST)"
declare -x RSYNC_CMD
for DIR_LIST in $DIR_LISTING; do
#	RSYNC_CMD="$(
#	printf "rsync -avz -e \"ssh -l ${SSH_USERNAME}\" $LOCAL_DIR%s $REMOTE_HOST\n" "$DIR_LIST"
	RSYNC_CMD="$( printf "rsync -avz -e \"ssh -l ${SSH_USERNAME}\" $LOCAL_DIR%s $REMOTE_HOST" "$DIR_LIST" )"
	printf "%s\n" "$RSYNC_CMD"
	echo $RSYNC_CMD >> temp.sh 
	source temp.sh
	rm temp.sh
done
exit 0
