07 08 | 2011

Useful options of rsync

Written by Tanguy

Classified in : Homepage, Debian, Command line, To remember

rsync logo

rsync is often used to back up systems, with options such as:

-a --archive
recurse and preserve usual attributes: symlinks, devices and special files, user and groups ownership, permissions and times;
-H --hard-links
detect and preserve hard links;
-A --acls
preserve ACLs, if you use them;
-X --xattrs
preserve extended attributes, if you use them.

In addition to these common options, rsync has plenty others, so everyone has his own recipe, but I would like to share two useful options I discovered.

--numeric-ids

By default, rsync uses literal UIDs and GIDs if it can find matches in both the source and the destination.

That is, if you have users jacquouille (1002) on your source system Reblochon, and a user jacquouille (1005) on your destination system Neufchâtel, rsync will map them: files with an UID of 1002 will be backed up with an UID of 1005.

This may or may not be wanted, but anyway you must be aware of it. For instance, if you have to restore Reblochon's home directories and do that by attaching a new drive locally to Neufchâtel, you will end with mixed up UIDs.

This option --numeric-ids forces rsync to use numeric IDs instead of trying to map them. It is notably needed for backups of jailed systems (BSD jails, OpenVZ, VServer, lxc…) which appear to have bogus IDs when seen from their host system because they have their own ID maps.

--fake-super

When you back up a full system or anything that requires keeping file ownership or device information, you need to have root privileges on the destination system. Without them, rsync would be unable to correctly chown() the destination files.

This option --fake-super offers a way to back up privileged information without requiring root privileges. It works by adding special extended attributes such as user.rsync.%stat containing al this information. Of course, it still requires a destination file system that supports extended attributes.

This provides a good way to push system backups without weakening your security by opening a root access on you destination system. For instance, I personally use it with rsyncd running as an unprivileged user.

2 comments

saturday 11 january 2014 à 20:47 Mike said : #1

Very good article on rsync. Here is one from around 1999 but still the very best rsync tutorial I've ever read. Explains it very well IMO: http://everythinglinux.org/rsync/

Admin edit: Replaced a commercial URL redirection by the real URL.

saturday 23 june 2018 à 20:02 Ron said : #2

Google led me straight to you, and the explanation of --numeric-ids

Thanks for putting this in plain language. :)

Write a comment

What is the last letter of the word dwuzt? : 

Archives