2

Is it possible to use the command line utility ditto to keep two folders in sync on a single OS X machine? In other words, does ditto copy only changed files from the source, and delete removed files from the target?

3 Answers 3

6

No, ditto does not copy just the changed files. You would be better off using rsync for this. Bombich, the makers of Carbon Copy Cloner, have a great article on their site about different tools.

About ditto:

Ditto is a command-line utility that ships with Mac OS X. Ditto preserves permissions when run as root and preserves resource forks by default. Ditto can be used to clone your system with the following step:

sudo ditto -X / /Volumes/Backup

About rsync:

rsync can be used to make a bootable clone as well. In addition to basic file copying, rsync also offers the ability to synchronize the source and target volumes -- it can copy only the items that have changed, thus subsequent clones, or backups, are much faster. The syntax is pretty easy:

sudo rsync -xrlptgoEv --progress --delete / /Volumes/Backup

However, I would highly recommend reading their detailed rsync document and upgrade to rsync 3.0.7 (I do it using MacPorts).

EDIT: OS X rsync 3.0.7 and metadata

To preserve metadata after installing the latest rsync, use the following command:

rsync -aNHAXx --protect-args --fileflags --force-change

This is from the bombich.com article. All these options may not always be needed, but this can be used to back up an entire hard drive as an example. That article also has a section on backup fidelity where they report the results from the backup bouncer test suite for rsync with the above options.

As an aside, to ensure that your files are being backed up properly, whichever method you use, the backup bouncer suite is very handy.

5
  • I use rsync on my linux server box, but have been wary of it on OS X due to the HFS "stuff", that I haven't cared enough about to learn about. :) Is there a way to make sure I have a HFS+ capable rsync?
    – Niko Nyman
    Jan 6, 2010 at 20:57
  • 1
    Good question. I've edited my post. I agree and can assure you that using rsync 3.0.7 and the options presented in the edit preserve all metadata. This has been tested using the backup-bouncer suite, and the results are located at the same rsync article at bombich.com: bombich.com/mactips/rsync.html
    – fideli
    Jan 6, 2010 at 22:45
  • 1
    A couple of compatibility warnings here: rsync v3 (per Bombich's notes) does a better job of preserving attributes than Apple's builtin rsync (v2.6.9 + Apple mods, which actually isn't that bad), but has incompatible command options (-E on Apple's version corresponds to -HNAX --fileflags on v3); to avoid confusion I tend to install v3 as rsync3. Also, the two versions pass extended metadata differently over the network, so remote syncs between versions can be messy. Jan 7, 2010 at 0:29
  • Thanks! I think installing v3 as rsync3 is a good idea, as I rely on rsync to do remote backups of my CentOS server and don't want to mess that up.
    – Niko Nyman
    Jan 7, 2010 at 14:42
  • 1
    Actually, if the CentOS rsync is version 3, and running on a filesystem with extended attributes (e.g. ext2-4), it might actually work better with v3 than the Apple version (although I think the worst that'd happen is that the xattrs won't get transferred). You can control which remote version is used with e.g. --rsync-path=/usr/local/bin/rsync3 Jan 7, 2010 at 22:13
1

I don't think ditto does what you believe it does.

If you want to sync two folders, consider rsync instead.

0

rsync syncs one way. if you want two way sync, use unison.

2
  • 1
    One way sync is enough for me.
    – Niko Nyman
    Jan 7, 2010 at 14:38
  • unison is of poor quality. It's nowhere near as good as rsync, which has been battle-tested for many years.
    – dhchdhd
    Mar 21, 2019 at 5:40

You must log in to answer this question.

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