5

Is it possible to DD one server to another? Maybe through SSH? I've looked around and I have seen examples of DD using SSH from local to server and vice versa, but is it possible to do it from server to server?

Another question that relates is what software does Digital Ocean use to create the snapshots of their servers that can then be later restored?

Thanks,

Daniel Sikes
  • 151
  • 1
  • 4
  • 1
    Note: using `dd` to clone a running, writable, mounted filesystem is likely to result in a serious mess. There are many ways to "backup" a live system, `dd` is not one of them. (if the drive/partition isn't mounted, then go for it.) – Ricky Jan 29 '14 at 05:44

2 Answers2

3

Sure, though it's a little clunky. You can do something like:

$ ssh server1 'dd if=/some/file' | ssh server2 'dd of=/new/file/path'

and it'll work. You could tweak the block side on both sides (pass bs=1m or whatever to both dd commands) for a speedup with some testing.

No idea about Digital Ocean: you'll probably want to ask them, or start another question here if you think someone might know.

Bill Weiss
  • 10,979
  • 3
  • 38
  • 66
  • Thanks Bill! Digital Ocean has 20 GB SSD's... That's what I am currently running. How long do you think it would take to dd them over ssh? I am gonna test it just to see but just wondered what your thoughts of a rough estimate would be. I've DD'd a lot of SD cards and stuff, and its really really slow... so I am wondering if it will be faster, or maybe slower? Your thoughts? Thanks! – Daniel Sikes Jan 29 '14 at 04:47
  • You'll be bound by a lot of things, whichever is slower: disk speeds on both sides, network IO, block size mismatch between network and disk... it _could_ be pretty quick if things go well. ssh isn't that slow :) – Bill Weiss Jan 29 '14 at 04:48
  • Haha! Thanks! I am setting up 2 fresh servers to test, and will post my results shortly. :) – Daniel Sikes Jan 29 '14 at 04:49
  • I'll say that I've moved a lot of data around like this, and it's never felt like the slow option. If you have a ton of data to move around you might want to poke at different `bs=` options in there, but I wouldn't worry much for a one-off operation. – Bill Weiss Jan 29 '14 at 04:51
  • What dir do I use if I am wanting a complete replica? I have 2 ubuntu servers exactly identical for the test. The difference is one has LAMP running, and the other does not. For my test to work, I want to be able to clone the first one (with LAMP) to the second one (without LAMP) and then reboot the second one, to see my "IT WORKS" page... – Daniel Sikes Jan 29 '14 at 04:54
  • If at least one of the hosts has "pv" installed, there's even a nice progress bar. E.g. `ssh server1 "pv -f file" | ssh server2 "cat > file"` – ckujau Jan 29 '14 at 09:00
  • You might want to use dump(1) if you've got the same filesystems on either side. dding the raw disk around isn't the best way to go. – Bill Weiss Jan 30 '14 at 04:10
1

A bit more efficient then SSH would be netcat nc as you wouldn't have the overhead of encrypting/decrypting your streams.

From the manual, create a listener on port 12345 on one side and make sure it is open in your firewall:

nc -l 12345 > filename.out

And then feed the data from your source server:

nc host.example.com 12345 < filename.in

The connection should close automatically after the transfer is complete.


In response to your comment to Bill, if you want to create identical machines by cloning the disks, that is typically done from outside the virtual machine, via the hypervisor, and not from within the OS.

The above will work well enough to clone disks/partitions/volumes from within the running OS as long as they are not mounted at the time, instead of files use the device entries in /dev/, but you can't use it clone the device that contains your root file system.

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • Thanks! I will be trying this approach to! You've been very helpful. I can't upvote this as I still don't have enough points, or else I would've... :) Cheers! – Daniel Sikes Jan 29 '14 at 13:41