1

I am trying to backup a remote server to my machine. I am trying something like

ssh user@ip "dd if=/dev/sda" | dd of=~/backup.img

But that obviously doesn't work. Other variants that don't work.

  • ssh user@ip "sudo dd if=/dev/sda" | dd of=~/backup.img
  • ssh user@ip -t "sudo dd if=/dev/sda" | dd of=~/backup.img

I have public key authentication set up. Note that even after compression, the remote machine can not hold its own backup. What do I do?

(Note in the long run I want to try and put this in an automatic script, but I just want a backup for now.)

Note: I should mention that I don't want to just back up the files (like with rsync) but to have a complete image that I can just drop on a new hard-drive should this one go belly up with little hassle.

terdon
  • 234,489
  • 66
  • 447
  • 667
PyRulez
  • 636
  • 1
  • 6
  • 19
  • 1
    using 'dd' is an incredibly inefficient way of backing up your disk, even if you want to have a complete image. If you wanted a true disk-level backup of your system, use your filesystem's 'dump' tool (for example, for ext2/3/4, use the [dump](http://linux.die.net/man/8/dump) command.) – jsbillings Jan 25 '14 at 22:40

1 Answers1

3

Something like this should work:

ssh user@ip sudo -S dd if=/dev/sda > backup.img 

You don't need to pipe to dd, you can just redirect the output into a file.

terdon
  • 234,489
  • 66
  • 447
  • 667
  • cool, works well with piping through gzip too – PyRulez Jan 25 '14 at 18:47
  • So how this works is the -S flag is on sudo, and it causes it to ask for the password from the typing terminal, not the machine its on, right? – PyRulez Jan 25 '14 at 21:44
  • @PyRulez Using `cat` instead of `dd` is [often a little faster](http://unix.stackexchange.com/questions/9432/is-there-a-way-to-determine-the-optimal-value-for-the-bs-parameter-to-dd/9492#9492): `ssh user@ip sudo cat /dev/sda >backup.img` (but you should heed [jsbillings's recommendation](http://unix.stackexchange.com/questions/110903/ssh-remote-backup-script#comment171516_110903) and use a proper backup tool). – Gilles 'SO- stop being evil' Jan 25 '14 at 23:33