6 ms·
I would probably have used tar|tar for this, or rsync.
by gaius 12y ago
I would probably have used tar|tar for this, or rsync.
- mturmon 12y agoAbout rsync: if you just use -a, it does not copy hard links correctly: -a, --archive [...] Note that -a does not preserve hardlinks, because finding multiply-linked files is expensive. You must separately specify -H. If you do specify -H, rsync does keep track of hard links, but presumably at the cost of keeping a data structure similar to cp: -H, --hard-links This tells rsync to look for hard-linked files in the source and link together the corresponding files on the destination. Without this option, hard-linked files in the source are treated as though they were separate files. [...] Of course, rsync could be more efficient at keeping track of the hard links than cp, but there's no reason to believe a priori that it would be.
- kazinator 12y agoDarn, thanks! I've been using rsync for incremental backups (themselves hard-link-based) for years, but neglecting to do this. That is to say, snapshot N+1 shares structure with backup N to save space (via hard links) via --link-dest. But files may be replicated because -H (missing) is orthogonal of --link-dest.
- ars 12y agoYou can use fdupes (or various others similar to it) to find and automatically hardlink the duplicates.
- __david__ 12y agoRsync has similar issues when you are copying hard links. It has to keep a table of all the inodes/filename pairs it sees so it can detect hard links and relink them on the destination. This can be big if you have a ton of hard links (say in a backup situation). Rsync at least acts reasonably idempotent, so you can just run it again if it gets interrupted, which is usually why I use it for large copies. I don't remember off the top of my head if tar handles hard links—it may be inappropriate for this usage.
- sitkack 12y agoIf you are often restarting rsync jobs or they fail over low speed WAN connections --partial keep partially transferred files Is your friend. Esp if you are trying to sync directories with multi GB files. Also if your media is bad or there is a failing piece of network gear along the path --bwlimit=KBPS limit I/O bandwidth; KBytes per second Can keep things running smoothly. It even works against disks, I have used it where an array would die if one attempted to read from it too quickly.
- Rapzid 12y agoWouldn't it only need to track the inodes with a link count above 1?
- justizin 12y agoTypically when copying from one machine to another, I've had the best results by far with tar | tar, but I'm not sure how well that would fare with tons of hard links like this. I think it's possible, but the default behavior would just gobble up umpteen copies of the same file.
- thrownaway2424 12y agoI would certainly have used cpio.
- thrownaway2424 12y agoDown voted because you disagree? Or you don't know what cpio is? Either way please discuss instead of or in addition to voting.
- voltagex_ 12y agoYour post has no information as to why you'd use cpio.
- thrownaway2424 12y agoOK, fair point. cpio doesn't have global data structures that grow with the size of the operation, which cp does have. rsync prior to 3.0 also had to scan the entire job before it would begin the transfer, which can take forever. cpio operates on a stream, in the form of find | cpio , so cpio only sees one file from the stream at a time. Find, at least GNU find, is also written such that its resources don't vary with the amount of output. rsync is a bit of a kitchen sink, and cp is too simple. cpio is just the thing, and was designed for this exact use case.
- lysium 12y agoDoes your setup preserve hard links? Because this is from where OP's problems originated.
- thaumaturgy 12y agoYou're right to recommend a tarpipe. I've had to copy several very large BackupPC storage pools in the past, and a tarpipe is the most reliable way to do it. (The only downside to BackupPC IMO...) For future reference for other folks, the command would look something like this: cd /old-directory && tar czvflpS - . | tar -C /new-directory -xzvf - Tarpipes are especially neat because they can work well over ssh (make sure you have ssh configured for passwordless login, any prompt at all will bone the tarpipe): cd /old-directory && tar czvflpS - . | ssh -i /path/to/private-key user@host "tar -C /new-directory -xzvf -" ...but tarpipe-over-ssh is not very fast. I have a note that says, "36 hours for 245G over a reasonable network" (probably 100Mb). Disk-to-disk SATA or SAS without ssh in between would be significantly faster.
- LeoPanthera 12y agoThe prompt goes to stderr, the pipe only pipes stdout, so a prompt should not cause excessive bonage, as long as you're there to respond to it. Also, don't use -z locally, or even over a moderately fast network. The compression is not that fast and almost always makes things slower.
- thaumaturgy 12y agoGood to know! Also, re: bonage, I agree that it "shouldn't", but it definitely did. From my sysadmin notes file: > The tar operation kicks off before ssh engages; having ssh ask for a password seems to intermittently cause problems with the tar headers on the receiving end. (It _shouldn't_, but it seems to.)
- pepve 12y agoOn modereately fast networks, instead of -z which uses a single threaded gzip implementation, parallel gzip may still give big improvements: http://zlib.net/pigz/ http://zlib.net/pigz/
- hnha 12y agoWhat's the benefit of using a tarpipe locally?
- vhost- 12y agoI'm unfamiliar with tar|tar, can you provide some incite into this trick?
- brazzy 12y agoNot much of a trick, the first tar serializes the entire directory structure including all the metadata into a stream of bytes, from which the second tar reassembles it. Basically the same as tar's standard usage, except you don't store that stream as a tar file/image anywhere.
- fsniper 12y agoOk, In this case why use a file to file copy like tar,cp, or rsync instead of a block copy like dd?
- jwr 12y agoThis. I guess anyone who began using UNIX systems back in the SunOS days or earlier would never think of using cp for this job. Well, mostly because the vendor-provided cp usually sucked badly (no recursive copy), but also because tar has always been such a great, reliable tool. The only disadvantage of tar is its peculiar syntax, but that's something you get used to.