Setting up rsync as a daemon
Background
The Unix utility rsync is a powerful tool for synchronizing data. It can be used to quickly and efficiently copy files both locally and remotely. It is best known for its delta-transfer capability which can greatly reduce the size of the data copied which results in a much faster copying process.
Setting up rsync as a daemon provides your system with an automated means of running the rsync process on-demand. Essentially, it provides instructions to the operating system on how to respond when faced with an incoming rsync connection. The daemon can be configured to limit access, require encryption, restrict permissions, etc. in order to ensure it provides a safe, reliable service. When run as a daemon, rsync is often referred to as rsyncd.
Special Notice
Improper use of rsync can permanently damage your files. The standard installation of rsync installed with Mac OS X Server was not designed to handle the resource forks that are sometimes associated with Macintosh files. Using rsync on files with these properties may result in irrecoverable file loss. Use of rsync should be limited to files known to be “safe” (e.g. Unix utilites and data files).
Setup
There are several steps necessary to setup rsync as a daemon process. First, a property list file (.plist) must be created specifying the appropriate arguments for the operating system’s LaunchDaemon process to instantiate rysncd. A configuration file (.conf) must also be created providing additional rsyncd runtime arguments. The configuration file may also include module files for easier control over individual settings. Finally, a secrets file (.scrt) should be created to provide an additional layer of security to the rsync daemon.
A newer version of rsync is also available through MacPorts. It may be installed in addition to the version that comes with Mac OS X. The standard version of rsync can be found at /usr/bin/rsync, while the MacPorts version is installed by default as /opt/local/bin/rsync.
Property List File
The property list file is read by the LaunchDaemon process and contains instructions for starting the rsyncd process. The supplied rsync.plist file is suitable for installation on standard Mac OS X Server installations. It must be modified to reflect the alternate path (/opt/local/bin/rsync) if using the MacPorts-installed version of rsync.
- Login as Administrator.
- Download the rsync.plist file and make any necessary modifications.
- Copy the rsync.plist file to the
/Library/LaunchDaemonsdirectory.sudo cp rsync.plist /Library/LaunchDaemons
- Set the owner, group, and permissions on the rsync.plist file.
sudo chown root:wheel /Library/LaunchDaemons/rsync.plist sudo chmod 644 /Library/LaunchDaemons/rsync.plist
- Load the property list file with the Launch Daemon
sudo launchctl load /Library/LaunchDaemons/rsync.plist
Configuration File
The configuration file is read by rsync upon launching and provides environment, security, and other configurable parameters. It also provides the definitions for rsync module. Each module exports a directory tree as a symbolic name and can define not only the directory tree but also any unique permissions, patterns, or other configuration options.
In the example configuration, the file and directory structure specifications are detailed in separate files which are included by the main configuration file. This permits each module’s list of targets to be maintained independently.
There are a number of available configuration options of which the sample configuration file illustrates only a few. For more information, see the man page for rsyncd.conf.
- Login as Administrator.
- Download the example rsyncd.conf file.
- Edit the rsyncd.conf file and make any necessary changes for your installation.
- Copy the rsyncd.conf file to the
/etcdirectory.sudo cp rsyncd.conf /etc
- Set the owner, group, and permissions on the rsyncd.conf file.
sudo chown root:wheel /etc/rsyncd.conf sudo chmod 640 /etc/rsyncd.conf
Module Files
Module files are an extension of the main configuration file and are simply an easy method of isolating module-specific settings. The modules files are included by the main configuration file. A typical usage is to define the list of files and directories that are to be included (or excluded) in the rsync operation. The example rsyncd.core module file includes several important directories that are not backed up by Apple’s Time Machine.
Secrets File
The secrets file can be used to store authentication information for restricting access to any defined rsync modules. The usernames specified in the secrets file do not need to be actual users.
The format for the secrets file is simple: username:password (one entry per line). Bear in mind that some systems may have restrictions on the characters, length, or capitalization for either component.
- Login as Administrator.
- Download the example rsyncd.scrt file.
- Edit the rsyncd.scrt file and add the usernames and passwords for your system.
- Copy the rsyncd.scrt file to the location specified in your rsyncd.conf file
sudo cp rsyncd.scrt /etc
- Set the owner, group, and permissions on the file.
sudo chown root:wheel /etc/rsyncd.scrt sudo chmod 600 /etc/rsyncd.scrt