Mirror Your Web Site With rsync - Page 2
5 Configure server1.example.comNow log in through SSH on server1.example.com as someuser (not root!) and do this: server1: (Please do this as someuser!) mkdir ~/.ssh By doing this, we have appended the contents of mirror-rsync-key.pub to the file /home/someuser/.ssh/authorized_keys. /home/someuser/.ssh/authorized_keys should look similar to this: server1: (Still as someuser!) vi /home/someuser/.ssh/authorized_keys
Now we want to allow connections only from mirror.example.com, and the connecting user should be allowed to use only rsync, so we add
right at the beginning of /home/someuser/.ssh/authorized_keys: server1: (Still as someuser!) vi /home/someuser/.ssh/authorized_keys
It is important that you use a FQDN like mirror.example.com instead of an IP address after from=, otherwise the automated mirroring will not work! Now we create the script /home/someuser/rsync/checkrsync that rejects all commands except rsync. server1: (We still do this as someuser!) mkdir ~/rsync
chmod 700 ~/rsync/checkrsync
6 Test rsync On mirror.example.comNow we must test on mirror.example.com if we can mirror server1.example.com without being prompted for someuser's password. We do this: mirror: (We do this as root!) rsync -avz --delete --exclude=**/stats --exclude=**/error --exclude=**/files/pictures -e "ssh -i /root/rsync/mirror-rsync-key" someuser@server1.example.com:/var/www/ /var/www/ (The --delete option means that files that have been deleted on server1.example.com should also be deleted on mirror.example.com. The --exclude option means that these files/directories should not be mirrored; e.g. --exclude=**/error means "do not mirror /var/www/error". You can use multiple --exclude options. I have listed these options as examples; you can adjust the command to your needs. Have a look at man rsync for more information.) You should now see that the mirroring takes place:
without being prompted for a password! This is what we wanted.
7 Create A Cron JobWe want to automate the mirroring, that is why we create a cron job for it on mirror.example.com. Run crontab -e as root: mirror: (We do this as root!) crontab -e and create a cron job like this:
This would run rsync every 5 minutes; adjust it to your needs (see man 5 crontab ). I use the full path to rsync here (/usr/bin/rsync) just to go sure that cron knows where to find rsync. Your rsync location might differ. Run mirror: (We do this as root!) which rsync to find out where yours is.
8 Links
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning
Learn benefits of Simpana software.
View the Gartner Video




print: 

Recent comments
1 day 1 hour ago
1 day 2 hours ago
1 day 6 hours ago
1 day 11 hours ago
1 day 11 hours ago
1 day 19 hours ago
1 day 19 hours ago
1 day 20 hours ago
1 day 21 hours ago
2 days 9 min ago