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:
- Boot up with a live CD
- Drop into a console
- Create your partitions, make the filesystems and mount the filesystems (for the sake of this explanation, mount your partition on
/mnt/recovery
- Copy the archive file onto the mounted partition
- Extract the archive using
tar -xvjpf archive.tar.bz2
taking special note of the flags used in this process.
- 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.