# mkdir /root/.keys /root/.keys/storage
# chmod 600 /root/.keys
# chmod 600 /root/.keys/storage
2. Obtain and secure storage SSH client key 'id_dsa' in this folder
# chmod 600 /root/.keys/storage/id_dsa
3. Save following as rsync.sh
#!/bin/bash
# run as root
APPDIR="${BASH_SOURCE%/*}"
LOGFMT="%t %i %b %n%L"
# remove following comment if testing
DRYRUN=""
#DRYRUN=-n
SKIPDIRS="$APPDIR/skipdirs"
SSH=/usr/bin/ssh
KEY=/root/.keys/storage/id_dsa
RUSER=john
RHOST=storage.lan
function run_rsync {
/usr/bin/rsync $DRYRUN -axHv --exclude-from=$SKIPDIRS --delete-during --out-format="$LOGFMT" -e "$SSH -i $KEY" $2 $RUSER@$RHOST:$1
}
echo -e "\n========================================="
echo "RSYNC push : Started `date`"
run_rsync /c/backup/rpi /
echo "RSYNC push : Finished `date`"
4. Save following as skipdirs
# directories to exclude from backup
# skip in-memory interfaces to the kernal
/proc/*
/sys/*
# skip dev, same reason
/dev/*
# skip hard links / mount points
/boot/*
/tmp/*
/run/*
/mnt/*
/media/*
# skip application generated stuff
/var/www/mrtg/*
# skip logs & temp files
/var/log/*
/var/swap
5. Save following as rsync in /etc/cron.d
0 */8 * * * root /home/user/rsync.sh 2>&1 >> /var/log/cron/rsync/rsync.log
No comments :
Post a Comment