Backing up a CentOS webserver

LincLinc OwnerDetroit Icrontian
I have an old CentOS 5 webserver in an old Dell running a LAMP stack that has a bunch of old twisted code and configurations on it. Basically, if it died, that'd be the end of the setup because no one has the resources to redo it all. I'm not sure I could even remember enough to do it. And, it's important to an old client's business.

What's my best strategy for creating a backup that I could get the machine running again with without recompiling and reconfiguring all the things?

I have root access. I can physically get to the machine and could remove the hard drive if necessary to do this, but it's a bit of a drive if I gotta do that.

PS: I have no goddamn idea how to even mount a drive in Linux and have no idea what the state of the drivers are on this thing. I've never done anything with it physically since popping in the CentOS discs back in 2007.

Comments

  • HAI LINC!

    There are numerous ways of making a full system backup for any Linux distribution. They range from the simple to the super complex. I assume that you're going to want the simple, not so much the complex.

    rsync is your friend. It is the best tool for doing simple snapshot backups of a single system. In order to make a full snapshot backup of the whole server, it takes a bit of tweaking and scripting. Not sure how good your bash scripting chops are. I could probably help you build a backup solution if you want in my off-time. Get in touch with me if you want and I'll see what I can do.
  • LincLinc Owner Detroit Icrontian
    edited November 2012
    My bash scripting skills are purely amateur-level. Have done a bit, but mostly by example when any moderate complexity is involved.

    What would I be doing, rsync-ing the whole thing to my local machine?
  • ardichokeardichoke Icrontian
    edited November 2012
    If that's where you plan on keeping the backup, then yes.

    Actually, if you just want to make a single backup (not automate the process for unattended backup love) then scripting probably isn't necessary. You can just run the rsync manually. It will likely take a long time though, just throwing that out there.

    The most basic backup of a full linux system using rsync can be accomplished like so:
    rsync -aAXPe ssh --numeric-ids --exclude-from=exclude.txt root@[hostname]:/ /path/to/backup/directory/

    exclude.txt should be a plain text file with any paths, files or file name patterns you don't want backed up. One per line. At the very least, you will want the following in exclude.txt

    /dev
    /proc
    /sys
    /tmp
    lost+found/
    You may also want to exclude /var/lib/mysql (or wherever you are keeping your mysql backups) as rsync has no ability to make a clean backup of live mysql databases. You would then want to back up the databases through some other method (phpMyAdmin or simply mysqldump).

    The easiest way to restore from this after a failure would be to install a new server with a basic CentOS 5 build, set up SSH, then basically do the rsync in reverse to push all the data back to the server. Once complete, reboot and it should be back as it was when the backup was taken. Take special care not to overwrite /etc/fstab though unless you manually confirm that the old one will work. (It's a good idea to back it up, for reference purposes, but restoring it usually leads to disaster).

    We often use this method when a customer wants to upgrade a server to a larger drive. It works well.
  • LincLinc Owner Detroit Icrontian
    Cool, sounds good. Yeah, it doesn't need to be automated, the changes over time really aren't important, it's just the general setup that needs a snapshot once a year or whatever. Thanks!
  • Also, whatever directory you do that to, you'll probably want to compress afterwards. It's going to be big.
  • lmorchardlmorchard {web,mad,computer} scientist Portland, OR Icrontian
    edited November 2012
    Something else I've also done, is tar / gzip the whole file system to stdout over ssh and pipe to a local file. Something like this:

    ssh myhost.com 'tar -zcf - /' > backup.tar.gz

    I'm missing a whole bunch of important flags and details there, but that's the gist.

    The pro: You get a compressed archive on your local system. The con: If the process gets interrupted, you start over. The big nicety of rsync is that you can stop and restart it at any point and it'll pick up where it left off.
Sign In or Register to comment.