I would like to copy the entire file system hierarchy from one drive to another..i.e contents of each directory as well as regular files in Linux platform. Would be gratefull to know the best way to do that with possibly Linuxes in-built functions. The file system is a ext family.
migrated from stackoverflow.com Jul 7 '11 at 9:07
This question came from our site for professional and enthusiast programmers.
I often use
Presuming /mnt is the new disk mounted on /mnt and there are no other mounts on /.
the -x keeps it on the one filesystem.
This of course needs to be done as root or using sudo.
This link has some alternatives, including the one above
What you want is rsync.
This command can be used to synchronize a folder, and also resume copying when it's aborted half way. The command to copy one disk is:
The options are:
To improve the copy speed, add
Also consider adding
For a one shot local copy from one drive to another, I guess cp suffices as described by Wolfmann here above.
For bigger works like local or remote backups for instance, the best is rsync.
Of course, rsync is significantly more complex to use.
Why rsync :
Adding two useful bits to the thread re rsync: changing cypher, and using
As per Wolfman's post,
There is some discussion (and benchmarks) around the place about a slow CPU being the actual bottleneck, but it does seem to help me when machine is loaded up doing other concurrent things.
One of the other big reasons for using rsync in a large, recursive copy like this is because of the -u switch (or --update). If there is a problem during the copy, you can fix it up, and rsync will pick up where it left off (I don't think scp has this). Doing it locally, cp also has a -u switch.
(I'm not certain what the implications of --update and --whole-file together are, but they always seem to work sensibly for me in this type of task)
I realise this isn't a thread about rsync's features, but some of the most common I use for this are:
Incidentally, if I ever have to use windows, I use rsync from cygwin to do large recursive copies, because of explorer's slightly brain-dead wanting to start from the beginning (although I find Finder is OS X even worse)
Like Michael Safyan suggests above, I've used
This version is fairly specific to Gnome- and Debian/Ubuntu-based systems, since it includes subdirectories of users' home directories which are specific to Gnome, as well as the APT package cache.
The last line will exclude any directory named cache/Cache/.cache, which may be too aggressive for some uses: