Do you actually need a bit-for-bit copy of the entire remote disk? e.g. for digital forensics?
If not, if you just need a copy of the partitions and the data on them, you can save a lot of time and transfer bandwidth by:
- copying the partition table, e.g. with
sfdisk
.
For example:
ssh user@hostip sudo sfdisk -d /dev/sda | sudo sfdisk /dev/sdc
or in two steps with a tempfile:
ssh user@hostip sudo sfdisk -d /dev/sda > /tmp/sda.txt
sudo sfdisk /dev/sdc < /tmp/sda.txt
- using
partclone
to clone only the parts of the filesystem that are currently in use, ignoring all the empty space and deleted files etc.
For example:
ssh user@hostip sudo partclone.ext4 -c -s /dev/sda1 -o - |
sudo partclone.ext4 -r -s - -o /dev/sdc1
partclone
supports all common and some uncommon fileystems used on Linux (ext2/3/4, btrfs, xfs, etc) and Windows (NTFS, FAT).
partclone is packaged for most distros, including debian. sfdisk
is part of the util-linux
package.
You still need to solve the ssh / sudo issue, but @Gilles has given a good answer for that.
The easiest way to eliminate the password prompts is to do all of this as root (sudo -i
to get a root shell), so you don't need to preface every command with sudo
, and to (as root) run ssh-copy-id hostip
to install root@localhost's ssh key in ~/.ssh/authorized_keys
on hostip. Then you can run:
ssh hostip sfdisk -d /dev/sda | sfdisk /dev/sdc
ssh hostip partclone.ext4 -c -s /dev/sda1 -o - |
partclone.ext4 -r -s - -o /dev/sdc1
If you're running ssh-agent, you'll only have to type in the passphrase for root's key once at the most (or not at all if you've used it previously).
cat
is simple to use: it copies its input to its output. That's what you were doing withdd
, only slower. – Gilles 'SO- stop being evil' Nov 15 '15 at 00:19