Mirroring Files and Directories with rsync
With rsync, supplied by default on OS X, quick mirrors and backups are a command line away.
As its name suggests,
rsync
synchronizes files and folders
from one location to another. That location could be another
directory on your current machine, or any other
rsync-enabled machine that you have access to.
Using the rsync protocol, only differences between
files are transferred; if you’re transferring a 30MB
text file that had only a few spelling corrections,
you’ll transfer only those corrections, not the
entire 30MB. You won’t believe how much of a
time-saver this is until you turn your head back and realize
it’s finished.
I’ve always been fond of the learning-by-doing school of thought, so open up a Terminal and enter the following command:
% rsync -vaz ~/Library ~/BackupsLet’s break that down: rsync is
the name of our utility and -vaz are some flags
we’ve passed to it. By issuing an
rsync
--help at the command
line, we quickly find out what that means:
-v, --verbose increase verbosity -a, --archive archive mode -z, --compress compress file data
Archive
mode is a special rsync configuration that is
suitable for mirroring. As the manual suggests (see man rsync), archive mode is a quick way of saying you want
recursion and to preserve almost everything. In this case,
everything means permissions, ownership, file
modification and access times, and so on. The -z flag, for compression, is more useful when you’re handling mirrors or backups ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access