To backup a web site on a periodic basis (say once per night), onto my own computer, running Linux. Web site computer runs Linux as well.
Domain name of the web site computer is supposed to be mywebsite.com. Web site files are supposed to be in /var/www/website directory.
Backup directory on my own computer is supposed to be /home/myself/backup.
We will use rsync over ssh to copy files from the web site to the local computer. ssh will be configured to use the public/private keys authentication mechanism, so that no password will be used.
The rsync command will be run every night thanks to cron.
This method is largely inspired by this article (additionnally, this article describes how to replicate a mySQL database...).
rsync -avz -e ssh backup@mywebsite.com:/var/www/website /home/myself/backup/website/
sudo mkdir /root/rsync sudo ssh-keygen -t dsa -b 1024 -f /root/rsync/mirror-rsync-key
sudo scp /root/rsync/mirror-rsync-key.pub backup@mywebsite.com:/home/backup/
mkdir .ssh
chmod 700 .ssh
mv mirror-rsync-key.pub .ssh/.
cd .ssh/
touch authorized_keys
chmod 600 authorized_keys
cat mirror-rsync-key.pub >> authorized_keys
command="/home/backup/rsync/checkrsync",no-port-forwarding,no-X11-forwarding,no-pty
#!/bin/sh
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\(*)
echo "Rejected"
;;
*\{*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
*\<*)
echo "Rejected"
;;
*\`*)
echo "Rejected"
;;
rsync\ --server*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac
chmod 700 ~/rsync/checkrsync
00 05 * * * /usr/bin/rsync -avz --delete -e "ssh -i /root/rsync/mirror-rsync-key" \
backup@mywebsite.com:/var/www/website/ \
/home/myself/backup/website/
This will start the rsync copy every night, at 5 AM.