3.12. Backing Up and Restoring with the ditto Utility
is a Mac OS X recursive copying utility, which can also create archive files (like
). What makes it interesting is that it's the one native tool with the ability to create full
can copy files and directories to one of three types of destinations: a directory, a ZIP archive file, or a
archive file. It does not support copying directly to tape. On the other hand, it doesn't come with Yet Another Archive Format, so you won't get stuck with backup archives in some format that might not be easily readable in a few
3.12.1. Syntax of ditto When Backing Up
The most common use of ditto is to make recursive copies of files and directories, like so:
$ ditto V --rsrc src... dest_dir
flag shows everything that
is copying. The
flag ensures that HFS+ attributes and resource forks are
Using ditto like this is a lot like using cp R , with one big difference. Let's say you want to make a copy of a directory. Using cp R src_dir dest_dir , you'd end up with the contents of src_dir under dest_dir/src_dir/ . With ditto src_dir dest_dir , the contents of src_dir end up directly under dest_dir/ , which can be somewhat confusing if you don't expect it. Also, ditto creates dest_dir/ if it doesn't already exist.
In most cases, ditto makes an exact duplicate of the source. However, there are a few things that ditto won't copy, in which case you'll be missing some information:
In addition to making straight copies of files and directories, ditto can copy them into an archive file. To create a cpio file (with optional gzip compression), use the command:
$ ditto V -rsrc c -z src_dir dest .cpgz
To create a ZIP file, use the command:
$ ditto V -rsrc c -k src_dir dest .zip
When creating a ZIP file, using the -sequesterRsrc flag stores extra HFS+ data in a directory named _ _MACOSX ; PKZIP-compatible utilities (other than ditto itself) may handle this better than AppleDouble.
As when making recursive copies, src_dir is lost from pathnames stored in an archive file. To retain src_dir in the archived pathnames, use the -keepParent flag.
One thing you can't do with ditto is selectively archive only part of a directory's contentsfor example, you can't use a filename pattern or make incremental backups. ditto is suitable only for archiving entire directory trees.
You can use ssh and dd to make backups to remote systems, the same way you can with tar or cpio . For example:
$ ditto V -rsrc c -k src_dir - ( ssh remote_host dd of= dest .zip )
3.12.2. The Options to the ditto Command
ditto is a very simple command, with relatively few options and a straightforward argument syntax. Here are some of the options you can use; refer to the manpage for more:
3.12.3. Syntax of ditto when Restoring
Restoring the contents of a ditto -created archive is done with the x flag (for "extract"). To restore from a compressed cpio archive, use the command:
$ ditto V -rsrc x src .cpgz dest_dir
The destination directory is created if it doesn't already exist. Note that the z flag isn't required; ditto automatically handles compressed cpio files.
To restore from a ZIP archive, use the command:
$ ditto V -rsrc x k src .zip dest_dir
There's nothing special about archive files created by ditto ; you could run extractions from any cpio or ZIP file using ditto .
If you want to restore only selected
184.108.40.206. Listing the files in a ditto archive
To list the files in a compressed cpio archive, use the command:
$ cpio itvz < src .cpgz
To list the files in a ZIP archive, use the command:
$ unzip lv src .zip