How to back up a running Linode server?
Solution 1:
So you want to backup all your drive without all those nasty mistakes and also filter out all the /proc and other temporary folders?
An option is to mount the root folder onto another folder within the filesystem, like this:
$ cd /mnt
$ mkdir drive
$ mount --bind / drive
This will give you all the files there are on your drive that are not deemed temporary (like the /proc or /sys folders).
Now that you have a clean view of your root folder, you can just copy it to your backup drive using standard cp
or rsync
. Something along the lines of:
cp -R /mnt/drive /mnt/backupdrive
This solves both your mentioned problems:
- You don't get into recursion, because the backup disk is not mounted within the drive (point of view)
- you don't miss any important files, because you are taking them all
See also: man mount(8)
Solution 2:
In Linux everything is a file. It's possible via rsync, but there are things to be aware of, that are (at best) difficult to get around.
You should think about replication first, especially for databases. Also this is a good idea to set up proxy / load balancer in front of your primary server, so you can easly switch back and forth with your primary and mirror servers during transition.
At the hardware level the best situation will be to have mirror-like server on another side, with the same number of ethernet ports, same hdd layout and so on. Everything that differs implies the need of system configuration changes.
i.e. if you have two eth ports, you want to make sure that network configuration, firewall and so on matches the interface name on both servers, and in case it differs you either need to change configuration after rsync or change the device name on the second (destination) server.
Same with partition layout. You should create same partitions as on your primary server, but if you create them from scratch you'll end up with diffrent UUIDs, so you will need to change fstab, grub, mdadm (if soft-raid is involved), and so on.
But, there are also many things that may go wrong, like databases, which can be inconsistent if not previously stopped (before doing rsync).
The best strategy will be to first prepare hardware and filesystem (partitions) - to match primary server's configuration. Then mount empty parititons via intermediary system (like live CD with ssh-server installed temporarily). You create empty /proc, /dev, /sys and then rsync the rest, like so:
rsync -avz -H --delete /etc /bin (...and so on) destserver:/mnt/yourrootfs/
Then you need to install grub on the device and work on configuration, to make it bootable, change network configuration, fstab and other stuff mentioned earlier.
You may also try to install fresh system (with same version that you're using on your primary server), then power it off, mount it via another, temporary system (like live cd), then replace anything other than /proc, /sys, /dev and /boot with rsync.
But it's only general idea. Things might complicate depending on what you actually have on this server, what is your configuration, network and hardware setup. And in the end of the day this might be really hard or impossible to do it without noticable downtime.
Solution 3:
What you actually want is restores. Whatever you do, you must restore test it regularly.
Linode has a backup service. The snapshots can be taken on a limited pre-defined schedule or with an API.
An advantage of snapshot based backups is that they offer a sharp point in time, as data isn't changing while a copy is made. Snapshots also can easily be restored to a different host, a new Linode in this case.