Backup with Rsync
Aus Weis nix
Create ssh key pair in backup location on the local system (here OSX):
cd /Volumes/BackupDrive ssh-keygen -t dsa -b 1024 -f rsync-key
Create backup.sh script containing on the local system:
#!/bin/sh SERVER=sample.remote.server if test ! -d $SERVER; then mkdir $SERVER; fi for FOLDER in /etc /var /home /root; do rsync -avz -e "ssh -i rsync-key" root@$SERVER:$FOLDER $SERVER done date >last-backup.txt
Install rsync on the remote system (here Debian):
apt-get install rsync
Create script /root/validate-rsync.sh on the remote system containing:
#!/bin/sh
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\(*)
echo "Rejected"
;;
*\{*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
*\<*)
echo "Rejected"
;;
*\`*)
echo "Rejected"
;;
*\|*)
echo "Rejected"
;;
rsync\ --server*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac
Copy public key portion created earlier from the local system to the remote system into /root/.ssh/authorized_keys file by copying or editing the file. Then place the following text before the ssh-dss part by editing the file:
command="/root/validate-rsync.sh"
Change permissions of the files on the remote system:
chmod +x /root/validate-rsync.sh chmod 600 /root/.ssh/authorized_keys
Check setup from the local system:
ssh -i rsync-key root@sample.remote.server ls Rejected rsync -avz -e "ssh -i rsync-key" root@sample.remote.server:/root/validate-rsync.sh . receiving incremental file list validate-rsync.sh sent 30 bytes received 205 bytes 52.22 bytes/sec total size is 289 speedup is 1.23
Now run the backup script to rsync all the specified folders from the specified servers.
