Is creating a sparse image using dd appropriate for backup/restore from a RAID?

5,096

Solution 1

Sounds like the device is remote. Assuming linux...

ssh remote_host 'dd if=/dev/sdb1' | cp --sparse=always /proc/self/fd/0 new-sparse-file

If local...

dd if=/dev/sdb1 | cp --sparse=always /proc/self/fd/0 new-sparse-file

This gives you an image that is mountable. However, if you pulled it across the network then you had 1.2 TB of network traffic (usually a bottleneck) and the CPU load of ssh and sshd.

If you are pulling that much across a network and network traffic costs you money...

ssh remote_host 'dd if=/dev/sdb1 | gzip ' | gunzip | cp --sparse=always /proc/self/fd/0 new-sparse-file

Solution 2

dd can create a sparse file, but you would have to manually tell it to copy every extent of used sectors in the filesystem, and you aren't going to do that.

What you are looking for is either Ghost4Linux, or clonezilla, both of which can be found on the Parted Magic live cd. They are smart enough to create an image file that only contains the used data, similar to Norton Ghost.

I still suggest that you use a proper backup tool like tar or dump instead of trying to image the drive. The down sides to image backup include:

  1. Can't selectively backup certain files
  2. Can't selectively restore certain files
  3. Can't restore to a smaller drive, even if it is large enough to contain the used data
  4. Can't do incremental backups
Share:
5,096

Related videos on Youtube

Ian Renton
Author by

Ian Renton

Updated on September 18, 2022

Comments

  • Ian Renton
    Ian Renton almost 2 years

    I have two non-networked servers, each with 1.2TB of storage in a RAID5 config on an LSI MegaRaid 9240-8i controller. I have been trying without success to get Symantec Ghost to image one machine to the other due to driver issues, and so I was wondering if it wouldn't be easier to boot from a Linux LiveCD, plug in an external hard disk and dd the RAID partition to the external disk.

    The 1.2TB partition only has around 10GB of data on it, so I hope to generate a sparse image file (to avoid having to find a 1.2TB USB disk!). I have seen people use the seek parameter of dd to achieve this - is that an appropriate way to create an image of around 10GB size in this situation?

    Even if this is a sensible way to generate a sparse image, is this a sensible way to mirror one RAID to another of identical configuration, or do the commercial utilities such as Ghost and Acronis do some 'magic' that dd does not?

    • derobert
      derobert over 12 years
      This work has already been done for you: clonezilla.org
  • psusi
    psusi over 12 years
    Unused sectors don't necessarily contain all zeroes. You could dd /dev/zero to a file until it uses up all free space on the disk, then delete it, and that would leave most of it filled with zeros, but when you try to restore this image, a lot of time will be wasted writing out all of those zeroes.
  • Ian Renton
    Ian Renton over 12 years
    Thanks - none of those down-sides are an issue with this specific job, but the Parted Magic CD certainly looks like a handy thing to have around, so I'll give G4L and Clonezilla a try.
  • Ian Renton
    Ian Renton over 12 years
    I can accept, I can't upvote until I have 15 rep :)
  • poige
    poige over 11 years
    Really good answer (and should be marked as the answer, as well). I'd suggest using shell's <() instead of /proc/…, though, like: cp --sparse=always <(ssh remote_host dd if=/dev/sdb1) destfile. And if there're lots of zeroes inside, ssh -C can be handy.