I have a broken disk where I need to copy a 60G file from.
From time to time the disk resets and I can't finish the copy.
I would like to try and copy partial slices and put them all together.
How can I do this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityUse ddrescue
, which is designed for this type of scenario.
It uses a log file to keep track of the parts of the data that it has successfully copied - or otherwise. As a result you can stop and restart it as many times as necessary, provided that the log file is maintained.
Use dd
.
It can do a lot, but you need the following form:
dd if=<source> of=<destination> bs=<block size> count=<blocks> skip=<offset>
E.g., to copy the 2nd to the 4th kilobyte from a file, you'd do:
dd if=in.dat of=out.dat bs=1K count=2 skip=2
Given the specifics of what you're trying to do, you can also try to add conv=sync,noerror
:
dd if=in.dat of=out.dat bs=1K count=2 skip=2 conv=sync,noerror
The noerror
makes it try to continue when it encounters an error, and the sync
makes it pad failed blocks with zeroes. So ideally, you'd get the file you want, but with zeroes for the blocks it couldn't read. However, it depends on your harddisk what it'll actually do. Some harddisks just shut down when they see an error, and then you still won't get your data.
dd
.split -b[bytes] yourbigFile
ddrescue
or no - you're probably going about it wrong. Because the file depends on the file-system, and because the file is very likely not contiguous, then doing the reads to get it from the faulty device is almost definitely going to require more disk-seeking than you can easily afford. I would Image the block device onto a known good device in as close to a single pass as I could get, and afterward focus recovery efforts on the mounted image file as much as possible.