Transferring content of block devices
For the purpose of backups, I’d like to transfer (several) whole disk partitions over an ssh link. 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 complainnot a regular file
tar
will try to recreate device inodes on the target sidersync
saysskipping 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.
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.
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.