In order to create regular backups, I'm using rsync together with --link-dest so as to create hard-links for unchanged files. For example:

rsync -ax \
      --partial --delete --delete-excluded --inplace \
      --exclude-from=/tmp/temp_excludes \
      --link-dest=/Volumes/Backup/current \
      /Users /Volumes/Backup/2012-06-25

This works very well as long as I start the process from my normal user account. Though as soon as I start the process using sudo it behaves erradically, meaning that rsync copies all the unchanged files instead of hard-linking them.

Since sudo modifies the environment, I've already also tried sudo -E in conjunction with making sure that my sudoers file has the corresponding option set. Well, that didn't work either.

So, the question is, how can I run rsync using sudo? Whereas the above example only shows a backup of the Users directory, I also need to backup some system files that I can only access as root.

3 Answers 3


I suggest you start rsync with -i --dry-run in order to find out why it wants to copy the unchanged files. The -i option will print out all updates along with a code that specifies why rsync considers that the files have changed (checksum, timestamp etc...). See the man page for a full explanation of the code.

You should probably also specify --numeric-ids in case the user ids are different on the source and the destination system.

  • Thanks, I'll give it a try! My guts also tell me that it might have to do something with the "ignore ownership" flag of OS X that seems to be set as default for external devices (yak!).
    – fotNelton
    Commented Jun 25, 2012 at 11:44

If you use LBackup (an rsync wrapper) for your backup, one of the checks it performs when running on an OS X system is that the permissions for the destination disk image / drive are enabled.

If the permissions are not enabled, the backup will not proceed, a warning will be issued the command to enable permissions.

You may also find this documentation page from the LBackup project to be of interest should you wish to continue using your own script.


Although Oliver's suggestion is really appreciated, the solution to the problem is as follows:

When (external) devices are mounted on OS X, they have their corresponding "ignore ownership" flag set by default. OS X maintains a special database for that, accessible via vsdbutil (deprecated) and diskutil.

According to some googling, the reasoning behind this seems to be that the typical OS X user is a consumer product user who want to access their data that have been stored e.g. on an external USB disk from any other computer without going through the hassle of ownership, permissios, etc.

Hence, it is vital for the desired backup solution using rsync and sudo to turn off this flag:

# sudo diskutil enableOwnership <yourDeviceHere>
sudo diskutil enableOwnership /Volumes/Backup

Then, unmount and mount that device again to make sure that everything works fine. Finally, I have updated my rsync call to the following:

rsync -aNHAXx -i --fileflags --force-change \
      --partial --delete --delete-excluded --inplace \
      --exclude-from=/tmp/temp_excludes \
      --link-dest=/Volumes/Backup/current \
      /Users /Volumes/Backup/2012-06-25

The thing is stuffed into a (slightly modified) bash script now and allows for incremental daily backups onto an external USB disk under OS X.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .