Right now we have a HD failure (bad sectors). Only certain files are affected. Our DC is giving us 72 hours to migrate the the content from the primary harddisk to a secondary harddisk.
The problem is that the primary HD has not just a lot of data, but custom softwares, configs etc that we would hate to redo again.
Would it be possible to just mirror the HD content and fix the corrupted data from the primary HD to the secondary HD? Would everything work fine? What is the best way to do this?
Looking for advice, thank you!
If the drive is failing already (read errors) then dd is not enough.
You should use ddrescue (the gnu version).
eg
The first pass skips ahead on read errors, the second tries hard to fill in the gaps. The logfile is very important !
If you can't turn the machine off then try a hard drive usb adapter. It's not the writes that will be slow, but reading the damaged sectors.
Yes, it's possible to "mirror" the HD to a new disk, and there's a number of ways to do it. As far as "the best way" to do it - well, that's subject to ones environment, your level of experience, etc.
If you are looking for tools that can help, look at the GParted Live disk. Then there's Ghost 4 Linux, etc.
If your data isn't being actively accessed, you can also simply copy (cp -pr ..., rsync, etc) the data from the failing HD to the new HD, you just have to omit things like {dev, lost+found, sys, proc, ...} depending on your distro and the like. Once the copy has completed, you have to re-run Grub (or lilo) and add it back to your master boot record et al. Obviously there's a bit more to the manual route... but it's not as bad as one might think.
In our environment, I've even created a live cd that pulls down archived data from TSM (Tivoli Storage Manager) that can be used to effectively do "bare metal restores".
You really have a number of options. It ultimately boils down to your level of comfort and the function of the box in question. Have a peek at GParted live, for certain. It has a number of features that make these kinds of things cake; like copying and pasting partitions ;).
if you have access to the machine, plug another blank hard drive in it, and run:
that going to clone the crashing hardrive to the blank one block by block. you can then reuse the new harddrive as your primary and fixe the files that might be corrupted.
If I understand your questions properly, secondary harddrive would be the blank harddrive (make sure it's empty before your start the cloning, it's a block by block copy so it won't care if anything already exist on the target).
Grandma tip: when hard drive is crashing and throwing errors, put it in the freezer (yes, freezer) for two hours then retry the cloning process.
Just an additional hint. If your failing HDD has faulty sectors, you may end up with a few scenarios:
Be prepared for quite a bit of repair work after the copying is done.