If you don't need versioning or encryption here's a simple script that uses rsync to mirror select folders on a Linux host to a remote backup server.
#!/usr/bin/env bash
# Script to mirror host folders to backup
SHOST=$(`hostname|cut -f1 -d.`)
THOST='mybackuphost.example.com'
TROOT='/d1/backup';
EXCL='/usr/local/etc/excludes.conf'
SDIRS=('/etc' '/root' '/home' '/usr/local/bin' '/usr/local/etc' '/var/spool/cron/crontabs');
LOGFILE=/d1/logs/backup/mirror_host.log
TIMESTAMP=`date +%Y%m%d%H%M%S`
echo "${TIMESTAMP} Mirror ${SHOST} to ${THOST}" >${LOGFILE}
for SDIR in ${SDIRS[@]};
do
rsync -avzR --exclude-from=${EXCL} --delete --log-file=${LOGFILE} ${SDIR} ${THOST}:${TROOT}/${SHOST}/
done
TIMESTAMP=`date +%Y%m%d%H%M%S`
echo "${TIMESTAMP} Mirroring completed" >>${LOGFILE}
The rsync options used here should be familiar, except for "-R", which preserves the full folder paths (without -R '/usr/local' would be mirrored as 'local', and '/var/spool/cron/crontabls' as 'crontabs'. It also will avoid unwanted deletions where a subfolder name shows up more than once, like '/home' and '/d1/home'.
Here is my excludes.conf file:
; Exclude file for rsync job (mostly targetting home directories)
tmp/
Downloads/
.cache/
.dbus/
.gvfs/
.mozilla/
.config/google-chrome/
Projects/
*/Cache/
.local/share/Trash/
lost+found/
.local/
.config/
node_modules/
.npm/
.nvm/
.gem/
.rbenv/
.vscode/
.eclipse/
.var/
*.sock
.virtualenvs/
.ssh/
.gnupg/
OneDrive/
GDrive/
.steam/
.gradle/
Updated this to reflect a re-ordering of the "--delete" and "--exclude-from" flags. My goals are to (a) filter out files that don't need backing up; and (b) delete any files in the target that have been removed from the source. The order "--exclude-from" ... "--delete" will accomplish both. I've also added the "--log-file" flag to capture info reported by the rsync as it runs, and expanded my exclusion list after some further experience.