I'm creating a compressed image of a laptop's internal drive into an external USB disk using a LiveCD GNU/Linux system. Also I use pv to monitor the progress. Here's how the command looks like:
dd if=/dev/sda bs=8M conv=noerror,sync | pv -pterab -s 298G / | gzip -c --fast > /mnt/backup/image.dd.bz
The USB drive is ADATA HD710. I know these drives tend to have a very loose USB plug - it can easily disconnect the drive if I move it. The process seems to be taking longer than I expected and I'm afraid I'll have to move the laptop and the drive. I'm afraid this will disconnect the drive, crash the duplication process and force me to do it all over again.
I've already checked if I can unmount the drive after pausing the process (with Ctrl+Z hotkey). It can only be done in "lazy" mode which means the drive isn't really being unmounted, it's only disconnected from it's mount dir. I waited until the drive finished work (stopped flashing it's LED) and unplugged it. I've plugged it again, mounted to the same directory that it was mounted before and resumed the process with command
Gzip has quit with I/O error.
Why? I couldn't unmount the drive even though dd was stopped, because the kernel knew it has opened file on that disk. After I removed the drive the opened file must have been closed, but wasn't reopened for the Gzip process to access after I re-mounted the drive. So when Gzip was trying to continue writing, it got an I/O error, because the kernel denied it's access to the file (which was unexpected).
I also tried stopping the process, adding skip=X (where X is the number of records dd reports to have written after it quits) and appending the rest of the disk image to the dd.gz file. However gunzip quits with an error saying:
gzip: data.dd.gz: invalid compressed data--format violated
I guess it could work if the image wasn't compressed.
Is it possible to stop the process (with Ctrl+C hotkey), and continue it appending to the previously created file? How to match the file positions? Will the two concatenated Gzip archives extract properly to restore the disk from it's compressed image?