Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to make a backup of a running server. Every config files and everything without turning it off.

How can I accomplish this? Is it ok to try copying it all? Because I had problems with the root directory.

I don't want to make a lot of experimentation also because it has an important configurations.

I'm trying to make all this via ssh. How can I do this backup?

Any Ideas?

share|improve this question
    
add comment

2 Answers

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)

share|improve this answer
    
Thanks a lot! I'll try this.. but the last part sounds a little complicated.. should i try to backup the boot part shutting everything off? .. To make it completely safe... –  AAlvz Feb 25 '13 at 18:09
1  
It depends on your goals. Just a backup of all files, including data, configuration files and OS files can be done with rsync or scp. That usually suffices. If you want to keep more copies around (e.g. a weekly backup) then look into backup software and or use rsync. Rsync can backup only the changes. If you want a full disk emergency recovery option then use the dd method. If the harddisk fails then you can replace it with a new (equal sized or larger) drives and restore/reinstall on from the image you made with the dd command. Or you can already write it to a disk and keep that as a spare. –  Hennes Feb 25 '13 at 18:24
1  
To do that, use nc -l 4242 | gunzip | dd of=/dev/sdb on the destination computer. (assume the spare disk on position 2). Note that a backup of the OS is nice, but you really want to set up something to regularly backup the data. Else if things crash and you restore a year old (disk) backup then you have a year old data. –  Hennes Feb 25 '13 at 18:27
    
You're good! .. thankyou .. Let me try it & I'll let you know! –  AAlvz Feb 25 '13 at 18:28
1  
If your source disk is written to while the copy is running then your destination copy will end up being inconsistent/corrupt. –  BigHomie Feb 25 '13 at 18:31
show 3 more comments

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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