dd/ddrescue style tool for SSDs that skips writes for identical blocks

3

I have a dd copy of a filesystem from a SSD I want to restore back to the same SSD filesystem due to a bad OS crash, putting it back into a known good state. 95% of the blocks will be the same, so to avoid wear on the SSD I don't want to have ddrescue write blocks to the SSD that are identical to the blocks in the dd copy.

Is there a tool equivalent to dd or ddrescue or command line flags to the tools that will not write identical blocks on the destination? It'll be slower since it'll do a read and optionally write, but I'm ok with the slowdown.

Blair Zajac

Posted 2012-08-06T01:33:27.980

Reputation: 201

1There's no way with standard tools to know what bits are written to which storage location. The controller abstracts this away. Go with Mechanical snail's suggestion. – None – 2012-08-06T07:19:15.333

Answers

3

It should be possible to do this using rsync, the differential data transfer tool.

See the man page, and use the --inplace option because you want to write directly into the device file.

That said, a single write pass across the disk is a trivial amount of wear, so consider just dding it over.

Mechanical snail

Posted 2012-08-06T01:33:27.980

Reputation: 6 625

Thanks, I use rsync all the time, but wasn't aware that --inplace works with device files. – Blair Zajac – 2012-08-06T16:18:19.530

It's not working with rsync 3.0.9 on RHEL5:bash-3.2#

$ rsync -P --inplace md0.image /dev/md0 
md0.image
 18883313664   2%  118.28MB/s    1:26:10
rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)
rsync: write failed on "/dev/md0": No space left on device (28)
rsync error: error in file IO (code 11) at receiver.c(322)     [receiver=3.0.9]
rsync: connection unexpectedly closed (28 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
 – Blair Zajac  – 2012-08-06T16:30:18.627

Turns out that even with --inplace, rsync 3.0.9 clobbers /dev/md0 first. – Blair Zajac – 2012-08-06T16:57:18.263

Is it trying to append? – Mechanical snail – 2012-08-06T17:28:04.723

0

e2image from e2fstools can do this with the -c option, but it can't read an input image from stdin as it seems to need to seek around.

The "old" dd_rescue tool (which is not the same as GNU ddrescue) has a -W option to avoid writes and can read from stdin: https://sourceforge.net/projects/ddrescue/ You might want -a as well to skip writing blocks of zeros, depending on the situation (I'm currently looking at restoring images to LVM thin pools while preserving the CoW characteristics.)

anarchetic

Posted 2012-08-06T01:33:27.980

Reputation: 171