When is -av NOT the appropriate option for rsync?
When should you not use rsync -av
?
tl;dr: When you don't want the behaviour provided by -a
or by -v
, don't use those options!
In addition, Gordon Davisson points out another exception:
if you aren't running it as root (on the destination system), or the user and group IDs don't match between source or target systems, you may not want to (/be able to) preserve users, groups, and device and special files.
And xenoid makes a point abut adding to -av
:
There are also case where you can add to
-av
,-av --delete
will replace the additive backup by a mirroring (use with care (ie, try first with-n|--dry-run
) otherwise you backup can be deleted if you match the wrong directories.
-v
(increase verbosity)
Easy one first: -v
. From the rsync manpage:
-v, --verbose increase verbosity
This one is pretty straightforward to see the effect of. If you're not concerned with transfer info, omit it.
-a
(archive mode)
Right, archive
mode. For this, it's worth having a read of What is archive mode in rsync? over on Server Fault.
Andrew's good answer lists the modes it includes:
-r, --recursive recurse into directories
-l, --links copy symlinks as symlinks
-p, --perms preserve permissions
-t, --times preserve modification times
-g, --group preserve group
-o, --owner preserve owner (super-user only)
-D same as --devices --specials
--devices preserve device files (super-user only)
--specials preserve special files
and excludes:
-H, --hard-links preserve hard links
-A, --acls preserve ACLs (implies -p)
-X, --xattrs preserve extended attributes
As he notes, it's perfect for backups; because if you are backing up you want to make an exact copy of the data you are backing up, along with information about the files.
Why wouldn't you want to use -a
, then?
Generally speaking, if you are in a situation where you don't want -a
, you'll know. Maybe:
- you want to copy files from a directory, but not its subdirectories (so no
-r
) - you want to copy symlinks are actual files =, because your destination filesystem doesn't support symlinks (no
-l
) - you aren't concerned about permissions (no
-p
) - you want to update modification times (no
-t
)
The last one is probably the most obvious use case.
Related videos on Youtube
leftaroundabout
Currently a PhD research fellow in maths and CS at Høgskulen på Vestlandet. In the past I have worked as a musician, as a programmer on magnetohydrodynamics number-crunchers, and studied geophysics.
Updated on September 18, 2022Comments
-
leftaroundabout over 1 year
I somehow never really get around to learning the use of
rsync
– whenever I need to do some copying/syncing, I think about it, then decide nah, I'll just usescp
.Which is probably not a good idea though, in particular
rsync
is clearly superior for updating a backup. If only I knew how to use it... whenever I've determined that I should really usersync
for a particular sync job, I then read up lots of man / internet advice, get utterly confused by the pleathora of options, try around several of them before actually getting the result I want, and quickly forget how I did it again.So, in order to get used to
rsync
at last, I'm looking for simple rules of thumb. In particular, it seems the “standard” use usually seems to involve the-a
flag, which the manual says means “archive” and lists some things it does, but leaves me confounded as to why I'd actually want them and in particular if I might have reason not to want some of them.Thus my question: if I make it a habit of copying files by default with
rsync -av
, what situations should I look out for when this is not a good idea?