djangoproject.com | python.org | nginx.org
version seven.
  http://demongin.org
demongin.org - rsync Refresher

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)
[Hawkon] are alot better in bed
[Hawkon] cause we had to hang tight with that wank till the damn nude pic got downloaded

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

  1. Install rsync if you haven't already:
    # root@chevette:~# aptitude install rsync
    
  2. 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'
    
  3. 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.
  4. Create an /etc/rsyncd.conf file. Here's mine:
    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
    
    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.
  5. Start it:
    chevette:~# /etc/init.d/rsync start
    
    Check it:
    chevette:~# netstat -anp |grep rsync
    tcp        0      0 192.168.64.61:873       0.0.0.0:*               LISTEN      7290/rsync      
    
  6. 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

  1. Make sure you've got rsync installed. See above (or Google it for your distro, etc.).
  2. Test the syntax of the command you're going to use. Here's mine:
    root@kumiko:~# rsync -Lavvz root@192.168.64.61::data /mnt/backup
    
    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.
  3. 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
    
  4. 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.