Can I clone a root file system of a running server via ssh?

If you want a backup all all the data then you can log in on the server via ssh and then simply copy all files. E.g. with scp or with rsync.

You can even copy everything including OS files if you use
rsync -zvr --exclude /dev/ / destination_computer_name_or_ip

-r: Recursive
-v: verbose
-z: Enables compression

Note this will not copy the boot record. To do that you want to copy the whole disk, and you want to do it when the disk is not mounted. (Read: Shutdown the machine you want to utterly_full_backup and boot from a liveCD or boot from another partition.)

Then use dd to read the whole drive.

Example code:

PC to store the backup on:
nc -l 4242 | gunzip | cat > my_full_disk_backup_of_PC_named_foo

And on the PC to back up:
dd if=/dev/sda of=- bs=1M | gzip | nc -p 4242 name_of_the_destination

dd will read from the disk. The whole disk, including boot sectors and empty sectors.
In the example we set it up for the first disk as indicated by sda. Adjust to sdb for the second disk, sdc for a third disk etc etc.

We output to std out, indicated by the -.

bs=1M sets a block size. You do not need this, but without there will be many small reads and huge overhead. Setting this to some value larger than 512 bytes or 4k will speed things up.

Next we pipe | the output though gzip to compress it. This assumes that your CPU will be a lot faster than your network. You can skip the gzip on the source and the gunzip on the destination, in which case you will send the raw data rather then compressed data over the network.

Last is nc or netcat. It accepts the input from the previous pipe and puts it on the network, toward port 4242 on a computer named name_of_the_destination.


On the receiving end we do the reverse:

Listen via nc -l for input on port 4242,

un-gzip if needed,

And finally write it to a file.


Important note:

You can do this while booted from the disk you are backing up. But there is no guarantee that the filesystem will stay the same during a backup. Thus only try that if you can boot with the disk as read-only. (e.g. purely using a ram disk)


what i would do is a lot similar to Hennes

i would create an iso file, download it, put it on disk or usb and upload a copy to dropbox just in case.

mkisofs -V LABEL -r DIRECTORY | gzip > backup.iso.gz

My friend hosts on rackspace, he told me that rackspace users have the option to create an iso file automaticaly, and if they were migrating to a new server, they could store the old backup on the old cloud server using rsync or whatever and shut it down, they still pay but its cheap.

I don't know if your hosting offers an automated backup system, or if you're paying for support. it's worth to ask them and maybe let them do it, if it's your first time.