--- /dev/null
+# Host and path of the backup location -- this can be localhost
+BACKUP_USER="slightlycyberpunk"
+BACKUP_HOST="192.168.42.42"
+BACKUP_LOCATION="/home/slightlycyberpunk/media/backups"
+
+# Array of directories on the local system to back up
+# Format is: "<path_to_backup>|<destination_folder>"
+LOCAL_PATHS=( "/home/slightlycyberpunk/|home" )
+
+# Array of remote directories to be backed up
+# Format is: "<user@hostname>|<path_to_backup>|<destination_folder>"
+# To give a specific user read-only access to be used for backups, use:
+# setfacl -R -m user:<username>:rx <directory>
+# Also need to set sudo permissions on 'umount .tmpmnt' in /etc/sudoers
+# <user> ALL = (root) NOPASSWD: /usr/bin/umount .tmpmnt
+#REMOTE_PATHS=( "slightlycyberpunk@remote.slightlycyberpunk.com|/home/slightlycyberpunk/|remoteannex" )
--- /dev/null
+#!/bin/bash
+cwd=`dirname $0`
+. ${cwd}/../etc/rsync.env
+
+
+YEAR=$(date +"%Y")
+MON=$(date +"%m")
+DAY=$(date +"%d")
+
+#######################################
+#### LOCAL FOLDERS ####
+#######################################
+
+
+for path in ${LOCAL_PATHS[@]}; do
+ # Cut up the path and extract each element
+ src=`echo $path | cut -d'|' -f 1`
+ dst=`echo $path | cut -d'|' -f 2`
+
+ # Make required directories on the remote server
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "mkdir -p ${BACKUP_LOCATION}/${dst}/full"
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "mkdir -p ${BACKUP_LOCATION}/${dst}/incr/$YEAR/$MON/$DAY"
+
+ # Run the rsync command and log to the remote server
+ rsync -avslhibx --inplace --delete \
+ --backup --backup-dir=../incr/$YEAR/$MON/$DAY \
+ $src \
+ ${BACKUP_USER}@${BACKUP_HOST}:${BACKUP_LOCATION}/${dst}/full | \
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "cat > ${BACKUP_LOCATION}/${dst}/incr/rsync.${YEAR}${MON}${DAY}.log"
+done
+
+#######################################
+#### REMOTE FOLDERS ####
+#######################################
+
+for path in ${REMOTE_PATHS[@]}; do
+ # Cut up the path and extract each element
+ login=`echo $path | cut -d'|' -f 1`
+ src=`echo $path | cut -d'|' -f 2`
+ dst=`echo $path | cut -d'|' -f 3`
+
+ # Make required directories on the remote server
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "mkdir -p ${BACKUP_LOCATION}/${dst}/full"
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "mkdir -p ${BACKUP_LOCATION}/${dst}/incr/$YEAR/$MON/$DAY"
+
+ # Temporarily mount the remote source filesystem
+ mkdir .tmpmnt
+ sshfs ${login}:${src} .tmpmnt
+
+ if [ $? -ne 0 ]; then
+ echo "Failed to mount remote path ${login}:${src}"
+ continue
+ fi
+
+ # Run the rsync command and log to the remote server
+ rsync -avslhib --inplace --delete \
+ --backup --backup-dir=../incr/$YEAR/$MON/$DAY \
+ .tmpmnt/ \
+ ${BACKUP_USER}@${BACKUP_HOST}:${BACKUP_LOCATION}/${dst}/full | \
+ ssh ${BACKUP_USER}@${BACKUP_HOST} \
+ "cat > ${BACKUP_LOCATION}/${dst}/incr/rsync.${YEAR}${MON}${DAY}.log"
+ sudo umount .tmpmnt
+done