Backup up a system with full read only permissions as root on a remote host and with snapshots.
The Backup server will be the one running the backup script and the remote host will be the client machine.
Without the validate-rsync script and the sender option, someone with your private key could erase your machine.
This will create a ssh private and public key
ssh-keygen -t rsa -b 2048 -f /root/cron/nas-rsync-key
Copy the public key to /root/.ssh/authorized_keys on the remote host.
add the following line in front of the key on /root/.ssh/authorized_keys
from="192.168.1.50",command="/root/cron/validate-rsync" [YOUR KEY HERE]
Create a file /root/cron/validate-rsync and make it excutable
#!/bin/sh
case “$SSH_ORIGINAL_COMMAND” in
*&*)
echo “Rejected”
;;
*(*)
echo “Rejected”
;;
*{*)
echo “Rejected”
;;
*;*)
echo “Rejected”
;;
*< *)
echo “Rejected”
;;
*`*)
echo “Rejected”
;;
*|*)
echo “Rejected”
;;
rsync –server –sender*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo “Rejected”
;;
esac
Backup script to backup the home directory:
#! /bin/sh
HOME="/media/Backup"
KEY=/root/cron/nas-rsync-key
date=`date "+%Y-%m-%d"`
rsync -avP -e "ssh -i $KEY" --link-dest=$HOME/current [email protected]:/home $HOME/$date/
For more details see http://troy.jdmz.net/rsync/index.html