Using vzdump snapshot to backup without downtime
By Ruben on Oct 8, 2007 | In Linux Hosting, OpenVZ | 1 feedback »
It's a while ago since I've written my last serious article but this one is really worth reading. The last few months I'm testing the possibilities to make Linux hosting more flexible and less independent on hardware. As an "Open source CentOS Linux enthusiast" I found OpenVZ. I cite: "OpenVZ is an Operating System-level server virtualization solution, built on Linux. OpenVZ creates isolated, secure virtual environments — VEs (otherwise known as virtual private servers, or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict."
After some tests I managed to get it running properly. Some VE configuration changes are necessary to let a virtual server work with Java JRE in a good manner.
Anyway, there's a tool called "vzdump" (http://wiki.openvz.org/Backup_of_a_running_VE_with_vzdump) to make backups of VEs.
There are 3 backup modes availabe:
1) bad (e.g. vzctl stop 101; vzdump 101; vzctl start 101)
2) better (e.g. vzdump --suspend 101)
3) best (e.g. vzdump --dumpdir /home --snapshot 101)
1 - bad:
==========
Only useful if you first STOP your VE in order to make a backup. Making an online backup without suspending the VE may lead to inconsistent data)
2- better:
==========
Sufficient in most cases. Makes an online backup with only a few seconds downtime of the VE. The vzdump tool takes care of stopping and resuming the VE. All services (e.g. Apache) are restored automatically.
3- best:
==========
Makes an backup without any downtime of the VE.
After pulling my hairs out, reading forums and trying all kinds of possibilities I've finally found the solution. In fact, it's quite easy but the lack of documentation makes it hard.
All you need to do is setup a Linux box like this:
Use LVM2 'volume group' (called 'sysvg') with these 'logical volumes':
- "/", type ext3, size 8 GB for example;
- "/vz", type ext3, size 8 GB for example;
- "/var/freespace", no filesystem required, size at least 512MB;
- "swap", type swap, size 2 times internal memory;
After the Linux installation has finished remove the logical volume freespace by entering the commands:
# umount /var/freespace
# lvremove /dev/sysvg/freespace
Now the the command vzdump --dumpdir /home --snapshot 101
(or likewise) should work!
Restoring a container can be done like this: vzdump --restore /home/vzdump-101.tgz 101
(or vzrestore /home/vzdump-101.tgz
101)
Also checkout the command vzmigrate
for moving VEs to a new host node (physical server).
Let me explain what happens. Vzdump makes a temporarily logical volume with type "snapshot" of 512MB and mounts it on "/vzsnap". (That's why you need at least 512MB free space in the volume group.)
This snapshot is taken from the logical volume mounted on '/vz'. And that's why all OpenVZ stuff (e.g. /vz and subdirs) needs to be in that '/vz'-logical-volume.
Okay, after vzdump has taken the snapshot of '/vz' all it has to do is travel down to the data of the selected VE and put in a "tar"-file. After this is done, the file will be moved to its final destination (dumpdir) and the temporarily "/vzsnap" will be deleted.
Good luck and let me know if this article is useful for you!
Tip: You should have at least 512MB free space available in the volume group. To check this, use vgdisplay and look for "Free PE / Size".
1 comment
Comments are closed for this post.
« bash_history not working in VE (virtual environment) of openvz | Speciale Joomla! hostingdienst gestart » |