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.
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.
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: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:
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:
/mnt/recovery
tar -xvjpf archive.tar.bz2
taking special note of the flags used in this process.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.
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
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.
Checkout Ghost for Linux. I've used it successfully for production projects. The command line interface is sufficiently intuitive.