Rsync on Solaris HOWTO

From Genunix

Contents

How To rsync a Pair of Directories

This procedure has been tested with the following versions of Solaris and rsync:

  • (rsync version 2.2.1 protocol version 19) - Solaris 2.6
  • (rsync version 2.4.6 protocol version 24) - Solaris 8
  • (rsync version 2.6.3pre1 protocol version 28) - Solaris 10

Please read this whole document as there are multiple options that can greatly change the behavior of rsync.

Syntax

Basic syntax with rsh

The basic syntax is simple enough. Here's a generic example that synchronizes the contents of a local directory - /dirpath/ - with a remote counterpart - remotehost:/dirpath/ using rsh as the transport protocol.

rsync -auv --delete --rsh=/usr/bin/rsh --rsync-path=/opt/sfw/bin/rsync /dirpath/ remotehost:/dirpath/

Gotchas

When rsyncing two directories, always remember the trailing slash on both the source and destination directory paths.

e.g. In our examples, we use remotehost:/dirpath/ rather than the incorrect remotehost:/dirpath

Using SSH connections

If, however, one is running on a system that does not accept rlogin connections (like most modern Solaris builds), one must use ssh as the connection method.

rsync -auv --delete --rsh=/usr/bin/ssh --rsync-path=/opt/sfw/bin/rsync /sourcedirpath/ remotehost:/targetdirpath/

(A third example is useful on Solaris 2.6 systems that are not ssh enabled) (Note: This example does not use the u or v flags, as it is run in the background, and we want to overwrite newer files. Nor does it specify the rsh path, as the default system rsh is used if not specified)

rsync -a --rsync-path=/usr/local/bin/rsync remotesourcehost:/dirpath/dir/ /archive/dirpath/dir/ &

Reverse direction

Finally, rsync can be run in the reverse direction should permission or security needs require it. That is to say, the above example rsyncs the local machine with its remote counterpart using the local box as the source.

Here's an example:

rsync -auv --delete --rsh=/usr/bin/rsh --rsync-path=/usr/local/bin/rsync remotehost:/sourcedirpath/ /targetdirpath/

Simple enough. You just change the order of the last two arguments.

Common Flags

One critical thing is to understand the flags I have listed. Read manpage rsync(1) for more info.

  • -a - archive mode... this basically says preserve everything (permissions, modification times, etc.) as well as to recurse.
  • -u - This tells rsync to only update a file if it is newer than the target file (When wanting to make two filesystems identical please drop this flag)
  • -H - preserve hardlinks
  • -v - verbosity.
  • --delete - This tells rsync to delete any files or directories on the target/destination filesystem that do not exist on the source filesystem. (This way file deletions on the source are replicated to the target). It IS CRUCIAL when using the --delete option to remember the trailing slash on both the source and destination directory paths. The trailing slash grounds the source and destination machines in the same exact directory, rather than having rsync erase everything in the current destination directory and create the root of the tree there.
  • --rsh= - Fully qualified path to the binary used to connect to remote host. (Generally rsh or ssh)
  • --rsync-path= - Fully qualified path to the binary used to run rsync on the remote host.

Running rsync as inetd service

Add an entry into /etc/inetd.conf

      rsync   stream  tcp     nowait  root    /usr/bin/rsync  rsyncd --daemon

when you run rsyncd as daemon it looks for /etc/rsyncd.conf . Below is an sample entry

       [space]
       path = /space/docs
       comment = Space docs
       read only = yes
       list = yes
       max connections = 50
       lock file = /tmp/rsyncd.lock