Bill Jonas on Mon, 31 Dec 2001 15:30:12 +0100 |
On Mon, Dec 31, 2001 at 08:28:29AM -0500, Michael F. Robbins wrote: > So is there an option I'm missing, or is there a better way to do this > alltogether? Tar is considered by many to be superior to cp for this purpose, although those views may or may not be valid since GNU cp has become quite good with preserving permissions, attributes, etc. Personally, I would probably do it like this: # Everything you did up to the cp command, then: (cd /mnt/home && tar -cpf - .) | (cd /mnt/backup && tar -xpvf -) Taken from http://duke.csc.villanova.edu/doc/LDP/HOWTO/Tips-HOWTO-2.html#ss2.6 (main Linuxdoc site is down, this is a mirror). A quick explanation of the above command: the parentheses create subshells (bash forks off a copy of itself for each set of parentheses it finds and executes the commands within the parentheses). The cd commands are pretty self-explanatory; the &&'s are used to prevent trashing the directory structures in case anything goes wrong during the directory change. (Not that it would or should, but caution.) "tar -cp" means "create, preserving attributes"; "f -" says that the output file should be standard output; and "." specifies the directory to tar up. "tar -xp" specifies "extract, preserving attributes"; "v" indicates verbosity (each filename will be printed to the console (well, stderr) as it's extracted); "f -" signifies that you want the file to be decoded to come from standard input. You can leave off the v if you don't care to see the progress of the command. That being said, "cp -a" *should* work correctly. With either way of doing it (tar or cp), you can check to see if anything is different with a command like so: diff <(ls -lAR /mnt/home |sed -e 's|/mnt/home||') <(ls -lAR /mnt/backup |sed -e 's|/mnt/backup||') |less Explanation: You probably know what diff does, so I don't belabor that here. What's really interesting is the "<()" construction. That's known as "process substitution". What it does is it gives a filehandle to the output of a process so that commands (like diff) which only work on files can be made to work on nearly any arbitrary output. The sed command replaces the specified string (/mnt/home or /mnt/backup, as appropriate) with nothing, to reduce false positives. The rest should be pretty self-explanatory. One thing to note: I've noticed that neither "cp -a" nor the tar method preserve the modification times of symlinks, so you might get many false positives. If you don't want to see the symlinks listed, you could add something like " |grep -v '\->'" or " |grep -v '^l'" to each command, just before the ). Hope that helps. -- Bill Jonas * bill@billjonas.com * http://www.billjonas.com/ Developer/SysAdmin for hire! See http://www.billjonas.com/resume.html Attachment:
pgp7Kn4MaLMgf.pgp
|
|