rsyncd setup on Mac OsX.

To set up an rsync server on a Mac can be quite tricky.

That’s my way to do that!

It is possible to simply launch rsync daemon by typing:

rsync –daemon

This will start a rsync daemon running on TCP port 873, but without the appropriate rsyncd.conf all the configuration has to be done by command line arguments.
In addition, if the server needs to be rebooted, the process will not restart automatically on boot.

On Mac OsX inetd is no longer an option since processes use launchd and launchdctl to load XML process files.

To launch rsyncd, The following plist (property list) file is installed as root into /Library/LaunchDaemons/org.samba.rsync.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Disabled</key>
        <false/>
        <key>Label</key>
        <string>org.samba.rsync</string>
        <key>Program</key>
        <string>/usr/bin/rsync</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/rsync</string>
                <string>--daemon</string>
                <string>--config=/etc/rsync/rsyncd.conf</string>
        </array>
        <key>inetdCompatibility</key>
        <dict>
                <key>Wait</key>
                <false/>
        </dict>
                <key>Sockets</key>
                <dict>
                        <key>Listeners</key>
                        <dict>
                                <key>SockServiceName</key>
                                <string>rsync</string>
                                <key>SockType</key>
                                <string>stream</string>
                        </dict>
                </dict>
</dict>
</plist>

The following is an example of a rsyncd.conf, located in /etc/rsync/rsyncd.conf as specified in the previous XML configuration file:

pid file = /var/run/rsyncd.pid
 
motd=/etc/rsync/rsyncd.motd
uid = nobody
gid = nobody
use chroot = yes
max connections = 5
syslog facility = local5
 
[myuser]
 path = /Users/myuser
 comment = Myuser's Home
 uid = myuser
 gid = admin
 list = yes
 read only = yes
 auth users = myuser_backup
 secrets file = /etc/rsync/rsyncd.secrets
 hosts allow = 192.168.0.0/24 1000:10:10::/64
 
[itunes]
 path = /Users/myuser/Music/iTunes/iTunes Media/Music
 comment = myuser's iTunes Archive
 uid = myuser
 gid = admin
 list = yes
 read only = yes
 auth users = itunes_backup
 secrets file = /etc/rsync/rsyncd.secrets
 hosts allow = 192.168.0.0/24 1000:10:10::/64

A file containing username and passwords has to be created under /etc/rsync and named rsyncd.secrets. Usernames and Passwords needs to be formatted as follows (referring to rsyncd.conf previous example):

myuser_backup:changethispassword
itunes_backup:changealsothisone

This file has to be owned by rsync process owner (root) and with 600 permissions:

# chown root:wheel /etc/rsyncd/rsyncd.secrets
# chmod 600 /etc/rsync/rsync.secrets

Once completed the basic setup, it’s time to launch the daemon. To do this simply use launchdctl to load the plist into the lauchd registry.
The easiest way is to run the command as follows:

sudo launchctl load org.samba.rsync.plist

At this point the rsync service is available and launchd will start the daemon once a connection attempt is made on the appropriate TCP port 873.

To test the service (from another host) simply submit a file list and statistics request to rsync server:

rsync --stats myuser_backup@rsync_host.example.ext::myuser

A prompt will ask for password (already defined in rsyncd.secrets file) and the rsync daemon will reply with file list and statistics.

At this point rsync server is ready to process requests (for example) issued from a NAS or a Linux Box for incremental backups.


Comments are closed.