Thoughts on data recovery

06.10.2005 11:39

Yesterday I spent five hours moving files from my old 40GB IBM DeathStar hard disk. After 4 years of service in my desktop it developed random bad sectors on the root and home partitions.

I found out that traditional Unix tools I used aren't really convenient for this task. I've read somewhere that the safest way to move a lot of data from one disk to the other is with tar like this:

$ cd /olddir
$ tar -c . | tar -C /newdir -x

This turned out to be a really bad idea. First, tar didn't restore hard links. I used hard links a lot in some hacks a while a ago and the copy of my home directory used far more disk space than the original. Second, tar has a weird idea of when to stop if it encounters a file it can't read. It will kind of continue after the error but won't copy everything it should. It will skip files that are perfectly OK.

The ordinary cp -a turned out to preserve hard links, but had the annoying property to stop at each corrupted file.

In the end the best solution I found was to use mv on each top level directory on the partition. It copied all files, skipped those that could not be read, but didn't delete anything from the source drive.

Posted by Tomaž | Categories: Code

Add a new comment

(No HTML tags allowed. Separate paragraphs with a blank line.)