![]() |
version seven.   http://demongin.org |
rsync Refresher
A quick refresher course on the basics of configuring rsync for a client-server pull.
Tuesday, 2011-02-01 | Programming
| [Hawkon] you know.. we (they guys who got on internet in the early 90's using 14.4kbps modems) |
| bash.org |
In case, like me, you've fallen off a bit where the sysadmin chops are concerned, here's a refresher course on using rsync to synchronize files down from an rsync server running Debian to any client running any linux.
Tendered with only terse explanations for the purpose of jogging the memory:
Server
- Install rsync if you haven't already:
# root@chevette:~# aptitude install rsync
- Modify your /etc/default/rsync file so that you can start the rsync daemon. Here is how mine looks:
RSYNC_ENABLE=true RSYNC_OPTS='' RSYNC_NICE='10' RSYNC_IONICE='-c3'
The default file will probably have a bunch of explanatory text; the guys who maintain the documentation on this stuff are the awesomest dudes. On the real.
- Create an /etc/rsyncd.conf file. Here's mine:
The thing in brackets (i.e. "[data]") is a "module". You'll use this module to write a simplified command on the client side. But more on that once we're done with the server.
motd file = /etc/motd max connections = 1 syslog facility = local3 hosts allow = 192.168.64.60 # kumiko address = 192.168.64.61 # chevette [data] comment = USB2 1TB data vault path = /mnt/data read only = yes list = yes uid = backup gid = backup hosts allow = 192.168.64.60 - Start it:Check it:
chevette:~# /etc/init.d/rsync start
chevette:~# netstat -anp |grep rsync tcp 0 0 192.168.64.61:873 0.0.0.0:* LISTEN 7290/rsync
- Use update-rc.d to make sure it starts and stops with the system:
chevette:~# update-rc.d -f rsync start 99 2 3 4 5 .
And that's it for the server.
Next step is to head over to the client and try to sync down from the server.
Client
- Make sure you've got rsync installed. See above (or Google it for your distro, etc.).
- Test the syntax of the command you're going to use. Here's mine:Remember the "module" name from above? That's the thing that we created in the /etc/rsyncd.conf file on the server. The path following the module is the path on the local machine.
root@kumiko:~# rsync -Lavvz root@192.168.64.61::data /mnt/backup
- Write a short script to do the rsync and log its output. Here's a simple one:
#!/bin/bash set -e LOG=/var/log/data_backup_log logger "data backup from chevette begins..." echo -e Start: `date` \\n > $LOG rsync -Lavvz root@192.168.64.61::data /mnt/backup >> $LOG echo -e \\n Finish: `date` >> $LOG logger "data backup complete!" exit
- Make sure it's executable and copy your script to some place where it will be run at regular intervals. /etc/cron.hourly is probably a reasonable choice.
And that's it: that should get you where you're going.
