Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

For the purpose of backups, I'd like to transfer (several) whole disk partitions over an ssh link. So the source is a block special device, and the target should be a regular file. Common tools seem ill-suited for this, though:

  • scp will complain not a regular file
  • tar will try to recreate device inodes on the target side
  • rsync says skipping non-regular file

My best bet currently is nc over a port forwarding, or one cat invocation on the remote side per partition, which means one password entry per partition unless one sets up public keys. Is there a more elegant solution?

Environment would be any reasonable Linux live system. Currently I happen to have a Debian wheezy lying around, but it should not be too specific to that.

share|improve this question
    
Please provide the OS, distribution and version you are working with. Althought I might have an alternative, I'd like to be sure that it applicable to your specific case. –  mdpc Aug 24 at 4:39
    
@mdpc: Linux, e.g. Debian wheezy. Updated my question to include that information. –  MvG Aug 24 at 6:01

2 Answers 2

You could pipe through SSH. Example using dd:

dd bs=1M if=/dev/disk | ssh -C target dd bs=1M of=disk.img

If the network connection breaks during transfer, you can resume if you know how much was copied. For example if you're sure at least 1000MiB were transferred already (check the file size of disk.img):

dd bs=1M skip=1000 if=/dev/disk | ssh -C target dd bs=1M seek=1000 of=disk.img

dd is just an example, it works just as well with other commands, as long as they work with pipes.

share|improve this answer
    
Why would you use dd? To slow things down? –  Gilles Aug 24 at 23:32
    
I love dd. It works great, and I don't have any complaints about its performance. YMMV. –  frostschutz Aug 25 at 10:08
    
What advantage does it bring compared to the simpler, less error-prone </dev/disk ssh -C target 'cat >disk.img', that would compensate the additional risk of error (if typoed as of is a biggie)? –  Gilles Aug 25 at 10:28
    
It lets you resume, for one thing. But we're arguing opinions here. It's pointless. You don't like dd, you use something else. It's that simple. As for typos, you can just as well confuse < and > and in many cases it's just as catastrophic. –  frostschutz Aug 25 at 11:21

I'd install the buffer program (if it is not already there in your distribution) if you are trying to transfer via an ethernet link. It is like dd but FAR better and faster. Basically it is programmed to do concurrent reads and writes using a shared memory buffer. I used to use this for tape dumps and it saved about 10% transfer time. The command line would be:

  buffer -i /dev/disk -m 100m | ssh -C target buffer -o disk.image -m 100m

There are more options available default blocksize is 10K. The above allocates 100MBytes of shared memory, you might have to adjust either this parameter or your configuration to allow this.

WARNING: Transmission of an ACTIVE partition in this manner will be problematic. So make sure that the partition to be transmitted is NOT mounted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.