3

I want to know is there a way to make a snapshot-like backup of a linux system into a single file and restore it in another system ?

You know in windows there are programs which makes a copy of a drive (like C:\ ) into a single image file. So you can restore this file later incase you are infected or something happens.

Every time I want to migrate my vps into another host, I have to setup the new server from scratch and move the files manually. Can I just make a snapshot backup of the whole system and restore it somewhere else (or on the same server) ?

I am not familiar with linux and I have no idea if this is technically possible or not ? Does the paritions, configs, system files,etc... are individual for each system ?

I heard about rsync, but that's not what I am looking for.

2
  • did you install your system on lvm volumes? If this is the case you could at least snapshot / clone these volumes.
    – Olivier S
    Jun 2, 2012 at 4:24
  • @OlivierS I am not sure what you mean by lvm. But all my vps systems are Xen + SoluVM. not sure if it's the answer.
    – Hassan
    Jun 2, 2012 at 11:59

5 Answers 5

5

While snapshot style backups are possible in some situations, they will not be useful in this situation. The main reason for this is that VPS providers rarely give you low enough level access to their system for you to be able to restore data in this fashion.

The real answer here is to use a config management system to manage your servers. Puppet and Chef are two of the most popular configuration management systems at the moment. With systems line these, you specify in a set of text files how you'd like your server to be configured, what packages you want installed, etc. These configurations then can be applied to any server, regardless of its location.

3
  • 1
    As a side note puppet may be used in a masterless mode which works well for VPS setups. Simply copy one directory to your new server to get an identical configuration. I have changed providers in this fashion a couple times. Jun 2, 2012 at 4:16
  • 1.Why there should be low level access ? 2.Doesn't a linux system have enough permission to access it's own data and partitions ? 3.Is the problem you are referring the restore part ? 4.And can you please name some of those "possible snapshot" backups ? Sorry but I need enough information to get know how linux works when it comes to backing up system. I did a little research on Puppet and it was interesting how it works. 5.But does that include solution for packages that you have to compile on your own ?
    – Hassan
    Jun 2, 2012 at 11:56
  • Although you didn't replied to my 5 questions, I guess your answer is ok. It seems there is no way to do such backup without having right permissions. Anyway I will try to learn Puppet.
    – Hassan
    Jun 4, 2012 at 15:53
2

Creating an image of a filesystem is entirely possible. In fact, for some distros such as Gentoo, this is actually the preferred method of not only backing up existing systems, but also deploying new systems based on an existing base install. Gentoo in particular compiles each package from source, so the quickest way to deploy a new installation is by tarring up an existing generic installation and extracting it onto the new system, thereby saving hours of compile time. This is called a Stage 4 installation, detailed on the Gentoo wiki.

However, in order to restore such an image, you will need boot the new system with a live CD, which might not be possible if you're running a VPS. If that isn't a problem, this is how you would go about archiving and restoring your system:


Archiving the System

When archiving an existing installation, there are a few caveats to be aware of, the most important being the list of directories that you should not include in the archive. For example, you certainly don't want to include /dev, and similarly, including the /proc directory would be somewhat pointless as well. Here is a generic list of directories that you should exlude when creating your archive:

.bash_history
/mnt/*
/tmp/*
/proc/*
/sys/*
/dev/*
/etc/mtab
/etc/ssh/ssh_host_*
/usr/src/*
/path/to/save/at/the_archive_file_you_are_creating.tar.bz2

Of course, this list would vary from distro to distro, but these are safe defaults for most systems. Take note of the last line in the list - you must include the filename of the archive file you're creating in the exclusion list.

To create the archive, use the following command:

tar cvjf /path/to/save/at/archive.tar.bz2 / -X excluded.txt

(where excluded.txt is a text file containing the list of directories to exclude.)

Here's a quick run-down of the flags used for creating the archive:

c - create archive
v - verbosely list files processed
j - use bzip2 compression
f - specify file name
X - use the specified exclusion file


Restoring the Archive

I must stress that this process will vary depending on the distro you're using. This process is heavily based off the process used in a Stage 4 installation for Gentoo, but the overall process would be fairly similar for other distros. The overall process goes like this:

  1. Boot up with a live CD
  2. Drop into a console
  3. Create your partitions, make the filesystems and mount the filesystems (for the sake of this explanation, mount your partition on /mnt/recovery
  4. Copy the archive file onto the mounted partition
  5. Extract the archive using tar -xvjpf archive.tar.bz2 taking special note of the flags used in this process.
  6. Create some basic device nodes:
    mknod -m 660 /mnt/recovery/dev/console c 5 1
    mknod -m 660 /mnt/recovery/dev/null c 1 3
    mknod -m 600 /mnt/recovery/dev/initctl p

Once you're done, you'll also need to configure GRUB to ensure your boot configuration is correct; this is the most likely place you'll trip up, so triple-check your GRUB configs to make sure everything is correct.

I highly recommend taking a look through the Stage 4 guide on the Gentoo wiki. It's a fantastic resource detailing exactly this process.

To summarise, this is the ideal solution to your question, but I suspect that since you're using a VPS, it's unlikely to be the most practical, since you probably won't have easy access to a DVD drive or an IPKVM switch to perform work on the system while configuring it from scratch. A word of advice, if you do decide to go this route, I suggest performing this procedure on a local machine a few times; it can get a bit tricky if you've never done it before, and the last thing you want is the pressure of running into non-trivial problems on a remote server when restoring the archive.

Update: I've just noticed that you say you aren't familiar with Linux. The procedure I've described here isn't trivial, so if you aren't too familiar with Linux you might battle with this. Unfortunately I can't think of an easier, reliable method for creating and restoring whole-system snapshots.

0

You are probably going to want to use some solution that understands the specific configurations, and can make a useful copy of the system configuration.

some examples of softwares that implement this strategy are;

http://www.cfg2html.com/
webmin backup
System Configuration Collector and blueprint

Another alternative is to migrate to a tool that understands the configuration, and which can be used to redeploy that configuration to another machine. Examples of this type of software are;

chef
puppet
cfengine

1
0

If all you want is a complete copy of your system you could use dd.

[as shown here 1] but, as discussed above, on a VPS this may not be totally useful to you.

0

Checkout Ghost for Linux. I've used it successfully for production projects. The command line interface is sufficiently intuitive.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .