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.

  • 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 command.) – jsbillings Jan 25 '14 at 22:40

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.

  • 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: ssh user@ip sudo cat /dev/sda >backup.img (but you should heed jsbillings's recommendation and use a proper backup tool). – Gilles Jan 25 '14 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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