Linux Box Admin
Trusted Remote Administration
logo

Tilde
What's new
Articles
Micro HowTos
About
Contact







disk images
(1 vote)
Thursday, 18 October 2007
   
    Disk images with ssh and dd    
     
       
 
There are quite a lot of backup utilities that can clone disks or partitions. I will talk about my favorites in one of other articles, but what if you didn't have such a tool ready and needed to do a block device backup? 
 
Linux is great because the basic set of it's utilities let's you do almost everything.
In this scenario I will take advantage of ssh capabilities to pipe output of a local command to a  remote command. Another necessary command is dd (disk dupe). Disk dupe can read and write raw input byte by byte.
 
You can use this simple approach to move directories as well as any block device.
To make a backup of a directory you usually use tar. In combination with ssh it would look like:
tar -cz directory | ssh host "dd of=directory.tgz bs=1k conv=sync,noerror"
 
Now you probably can see where I'm heading:
dd if=/dev/hda  bs=1k conv=sync,noerror |gzip -c |ssh host "dd of=/images/hda.gz"
 
In case you wonder what the dd parameters stand for, the if is input device, bs stands for how many bytes per read should dd take. These 2 parameters are obligatory for dd to do the job, but the conv=sync,noerror are necessary for the cloning. The first parameter tells dd to pad the block set through the bs option with zeros. The second one to continue on failed read/write.
 
Depending on the size of the block device and speed of the connection the image will be placed onto the remote location. Afterwards it is a good habit to test the archive by launching:
gzip -t /images/hda.gz 
 
If there is no output, the archive is ok.
 
To restore the image onto a block device you need to run this command on the machine where is the target block device located:
ssh host -c blowfish "cat /images/hda.gz"|gzip -cd|dd of=/dev/hda bs=1k conv=sync,noerror
 
 
 To conclude, the ssh/dd method is by no means the most effective one, but in case of emergency will give you a very fast option to make a whole partition or disk backup.
 
 
 
   
       
         
 

Copyright © 2006,2007 Linux Box Admin.

 
My NHL fan blog