Backing Up an Entire Linux Environment

I'm currently in the process of setting up and playing with my new Linux box. Being a newcomer to these things, I'm doing alright, but one small mistake can screw everything up for me. I've currently got Apache and some other things successfully installed and working how I want them to, and I really don't want to be able to screw the environment up.

What is the easiest way to backup the actual environment itself so that I can restore the backed up copy (with Apache etc. fully working) should I need to?


Solution 1:

So there's two things,

  1. back up your data and configuration files
  2. write down / record the commands you used to build the environment and why

For number 1, there are several options, one of which Alex has already mentioned. rsync is a nice approach, and I rsync everything I care about on my Linux VPS to a Linux machine here at home on a regular basis.

But for me, you can't beat #2 as well, and here's why. Just having the config file doesn't help if you can't remember why it's like that.

Sometimes I fight for ages getting Exim to do one little thing, make a change 400 lines deep into a config file, and then forget it.

Even if I don't recover the server from a backup, I might want to build another server later and do the same thing, but suddenly I can't remember how, and you can't necessarily copy config files verbatim.

So, as you build and configure your server,

  1. write down every command you run (i.e. apt-get, yum, dpkg --reconfigure exim4-config, etc.)
  2. make a note of config changes you make and why (i.e. added these 4 lines to /etc/apache2/apache2.conf because I needed X and Y)

Keep that build document up-to-date when you add packages or change configs and then if you need to build a new server from scratch, it's easy.

I run a news (Usenet) server, and I basically have a document which describes how to go from bare Debian Squeeze to fully working news server. If I lose everything, I can rebuild it in about 2 hours (obviously, no data, but full config). Same for my web server, I know what changes I've made to Apache and why, which perl and php modules are installed and why, etc.

That way you can focus on backing up your data, and config, but you won't ever have to restore the config to a fresh box (which I think can be risky due to potential software / distribution changes) and can instead follow your build sheet and then restore your data.

  • rsync for data and config
  • paperwork for config on top

Solution 2:

I usually use etckeeper for backing up configuration files in /etc (actually for revisioning them), I set it to perform commit every 20 minutes and BackupPC for backing up everything else. BackupPC is probably an overkill in your situation so I suggest you to use just rsync -a to some other host.