I have to copy a large directory tree, about 1.8 TB. It's all local. Out of habit I'd use rsync
, however I wonder if there's much point, and if I should rather use cp
.
I'm worried about permissions and uid/gid, since they have to be preserved in the copy (I know rsync does this). As well as things like symlinks.
The destination is empty, so I don't have to worry about conditionally updating some files. It's all local disk, so I don't have to worry about ssh or network.
The reason I'd be tempted away from rsync, is because rsync might do more than I need. rsync checksums files. I don't need that, and am concerned that it might take longer than cp.
So what do you reckon, rsync
or cp
?
I would use rsync as it means that if it is interrupted for any reason, then you can restart it easily with very little cost. And being rsync, it can even restart part way through a large file. As others mention, it can exclude files easily. The simplest way to preserve most things is to use the
-a
flag – ‘archive.’ So:Although UID/GID and symlinks are preserved by
-a
(see-lpgo
), your question implies you might want a full copy of the filesystem information; and-a
doesn't include hard-links, extended attributes, or ACLs (on Linux) or the above nor resource forks (on OS X.) Thus, for a robust copy of a filesystem, you'll need to include those flags:The default cp will start again, though the
-u
flag will "copy only when the SOURCE file is newer than the destination file or when the destination file is missing". And the-a
(archive) flag will be recursive, not recopy files if you have to restart and preserve permissions. So:When copying to the local file system I tend to use rsync with the following options:
Here's my reasoning:
I've seen 17% faster transfers using the above rsync settings over the following tar command as suggested by another answer:
When I have to copy a large amount of data, I usually use a combination of tar and rsync. The first pass is to tar it, something like this:
Usually with a large amount of files, there will be some that tar can't handle for whatever reason. Or maybe the process will get interrupted, or if it is a filesystem migration, the you might want to do the initial copy before the actual migration step. At any rate, after the initial copy, I do an rsync step to sync it all up:
Note that the trailing slash on
/src/
is important.rsync
Here is the rsync I use, I prefer cp for simple commands, not this.
cpio
Here is a way that is even safer, cpio. It's about as fast as tar, maybe a little quicker.
tar
This is also good, and continues on read-failures.
Note those are all just for local copies.
This thread was very useful and because there were so many options to achieve the result, I decided to benchmark few of them. I believe my results can be helpful to others have a sense of what worked faster.
To move 532Gb of data distributed among 1,753,200 files we had those times:
rsync
took 232 minutestar
took 206 minutescpio
took 225 minutesrsync + parallel
took 209 minutesOn my case I preferred to use
rsync + parallel
. I hope this information helps more people to decide among these alternatives.The complete benchmark are published here
Whatever you prefer. Just don't forget the
-a
switch when you decide to usecp
.If you really need an answer: I'd use rsync because it's much more flexible. Need to shutdown before copying is complete? Just ctrl-c and resume as soon as your back. Need to exclude some files? Just use
--exclude-from
. Need to change ownership or permissions? rsync will do that for you.The
rsync
command always computes checksums on every byte it transfers.The command line option
--checksum
only relates to whether checksums of files are used to determine which files to transfer or not, ie:The manpage also says this:
So
rsync
also, always, calculates a checksum of the whole file on the receiving side, even when-c/ --checksum
option is "off".rsync -aPhW --protocol=28
helps speed up those large copies with RSYNC. I always go rsync because the thought of being midway through 90GiB and it breaking scares me away from CPrsync is great, but has issues with really large directory trees because it stores the trees in memory. I was just looking to see if they'd fix this problem when I found this thread.
I also found:
http://matthew.mceachen.us/geek/gigasync/
You could also manually break up the tree and run multiple rsyncs.
You definitely want to give rclone a try. This thing is crazy fast :
This is a local copy from and to a LITEONIT LCS-256 (256GB) SSD.
You can add
--ignore-checksum
on the first run to make it even faster.