Clone/Back Up/Restore OpenVZ VMs With vzdump

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 11/20/2008

vzdump is a backup and restore utility for OpenVZ VMs. This tutorial shows how you can use it to clone/back up/restore virtual machines with vzdump.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

I’m using two OpenVZ servers in this tutorial:

  • server1.example.com: IP 192.168.0.100
  • server2.example.com: IP 192.168.0.101

(Both are using Debian Etch and are set up according to this tutorial: Installing And Using OpenVZ On Debian Etch – but it works with any other distribution as well.)

I’m running a virtual machine with the hostname test.example.com, the IP address 192.168.0.102 and the VEID 102 on server1.example.com, and I want to back up that machine and restore it on server2.example.com.

We can restore it on server2.example.com with no changes (e.g. same IP address and hostname), but in that case we must stop the VM on server1.example.com because otherwise the IP address and hostname would conflict; the second possibility is to restore it on server2.example.com, but change some parameters like the IP address and hostname with the vzctl set command – in this case we can run both VMs (the original one on server1.example.com and the clone on server2.example.com) at the same time. This is a great method to clone VMs.

2 Preparing The OpenVZ Servers

First we must install vzdump and rsync which is a dependency. On Debian, the command is as follows:

server1/server2:

apt-get install vzdump rsync

3 Creating A Backup Of A VM

(This chapter is for server1 only!)

On server1.example.com, I want to create a backup of my VM with the VEID 102. Take a look at

man vzdump

to learn how to use vzdump.

To back up all VMs on your server, you’d use something like

vzdump –compress –dumpdir /home/backup –stop –all

–compress means: compress the dump file (results in a .tgz).

–dumpdir specifies the directory in which you want to store the dump. If you don’t specify a dumpdir, it defaults to /vz/dump or /var/lib/vz/dump (depends on your distribution).

–stop stops the VM, creates the backup, and starts it again afterwards. Your VM can be down a few minutes if you use –stop. A faster solution would be to use…

–suspend: it suspends the VM; the VM is then copied via rsync to a temporary directory. The VM gets resumed right afterwards so that it’s down only a few seconds, and then the dump is created using the copy in the temporary directory. I recommend to use this one if you can’t afford long downtimes.

You can as well leave out –stop and –suspend and dump a running VM. In most cases this makes no problem, but it is possible that the dump is inconsistent, so be warned!

–all creates a dump of all available VMs. If you want to dump only a specific VM, replace –all with the VEID of the VM.

To create a dump of our VM 102 in /home/backup and stop the VM during the backup, use

vzdump –compress –dumpdir /home/backup –stop 102

To create a dump in the default directory (/vz/dump or /var/lib/vz/dump), use

vzdump –compress –stop 102

The output could look as follows:

server1:/vz/dump# vzdump –compress –stop 102
INFO: starting backup for VPS 102 (/var/lib/vz/private/102)
INFO: starting first sync /var/lib/vz/private/102 to /var/lib/vz/dump/tmp9009
INFO: stopping vps
Stopping container …
Container was stopped
Container is unmounted
INFO: final sync /var/lib/vz/private/102 to /var/lib/vz/dump/tmp9009
INFO: restarting vps
Starting container …
Container is mounted
Adding IP address(es): 192.168.0.102
Setting CPU units: 1000
Configure meminfo: 65536
Set hostname: test.example.com
File resolv.conf was modified
Container start in progress…
INFO: vps is online again after 15 seconds
INFO: Creating archive ‘/var/lib/vz/dump/vzdump-102.tgz’ (/var/lib/vz/dump/tmp9009/102)
Total bytes written: 340428800 (325MiB, 11MiB/s)
INFO: backup for VPS 102 finished successful (1.37 minutes)
server1:/vz/dump#

To not stop, but suspend the VM, use

vzdump –compress –suspend 102

This is a sample output:

server1:~# vzdump –compress –suspend 102
INFO: starting backup for VPS 102 (/var/lib/vz/private/102)
INFO: starting first sync /var/lib/vz/private/102 to /var/lib/vz/dump/tmp10842
INFO: suspend vps
Setting up checkpoint…
suspend…
get context…
Checkpointing completed succesfully
INFO: final sync /var/lib/vz/private/102 to /var/lib/vz/dump/tmp10842
INFO: resume vps
Resuming…
INFO: vps is online again after 4 seconds
INFO: Creating archive ‘/var/lib/vz/dump/vzdump-102.tgz’ (/var/lib/vz/dump/tmp10842/102)
Total bytes written: 340428800 (325MiB, 24MiB/s)
INFO: backup for VPS 102 finished successful  (1.57 minutes)
server1:~#

After the backup, take a look at the dump directory…

ls -l /vz/dump/

… and you should see a .tgz file:

server1:~# ls -l /vz/dump/
total 147864
-rw-r–r– 1 root root      1170 2008-11-20 17:40 vzdump-102.log
-rw-r–r– 1 root root 151249685 2008-11-20 17:40 vzdump-102.tgz
server1:~#

You can now copy the dump to the other OpenVZ server, e.g. with scp (this copies /vz/dump/vzdump-102.tgz to the /home directory on server2.example.com):

scp /vz/dump/vzdump-102.tgz root@192.168.0.101:/home

4 Restoring A VM

(This chapter is for server2 only!)

On server2.example.com, you can now restore the VM as follows…

vzdump –restore /home/vzdump-102.tgz 250

… where 250 is the new VEID of the restored VM – you can use any VEID that is unused on server2.example.com – you could even use 102 again if it is unused on server2.example.com.

If you don’t want to modify the settings of the VM (e.g. IP address, hostname), you can start it now, but please make sure that the original VM is stopped on server1.example.com because otherwise the IP addresses conflict:

vzctl start 250

If you want to run both VMs (the original one and the clone) at the same time, you must change the IP address and hostname of the clone before you start it.

To set a new hostname, run sonething like this:

vzctl set 250 –hostname test2.example.com –save

To set a new IP address, we must first delete the original one…

vzctl set 250 –ipdel 192.168.0.102 –save

… and then set a new one:

vzctl set 250 –ipadd 192.168.0.250 –save

Afterwards we can start the clone:

vzctl start 250

5 Links

./check.cgi & ./hnc.cgi & ./***.cgi ???

bunlar mail spam gateway proxy olarak kullanilan seyler.

abuse edilen bir php script vs ile servera yuklenip run ediliyorlar

run edildikten sonra da dosya siliniyor ve bulunmaz bir hale geliyor

serverdan bulup silmek icin en kolay yonem

#grep -r “check.cgi” /var/log/proftpd/.

olabilir

veyahut

updatedb

locate .pl diyip 2332832683276.pl diye bir dosya aramak da olabilir sonuclarda.

—————————

I think one of your domains in the server is hacked.. Can you do a grep -i hnc.cgi /var/log/messages got any results ?

if you didn’t got any results do this too..

zgrep -i hnc.cgi /var/log/messages.*.gz

also check if any hnc.cgi files is there in the server using find

cd /home; find -name “hnc.cgi” -type f

Any results ?

Somehow one of your ftp account/domain is hacked and it’s used to upload hnc.cgi or check.cgi script and they start running it… After running this script usually it will be deleted and hence you may not find this script if you use locate/find command. So the best way to check which account got hacked is to check the pattern hnc.cgi in the ftp logs..

After verifying the logs you may clearly see that it’s uploaded and removed after running that script.

yes hnc.cgi is used to send spams. If you find any patterns of hnc.cgi in /var/log/messages immediately you change the password for the account and ftp accounts..

Also just verify the files uploaded checking the logs and make sure the hacker didn’t modified your webfiles..

Hi all,

I had some issues with line drawing when accessing my linux box from work. I found the following workaround in this site:

To make it all work right, you need to twiddle the following configuration settings:

Terminal → Keyboard:

Change the sequences sent by: The Functions keys and Keypad:
Select Linux.

Window → Appearance:

Font settings:
Pick a font that contains the Unicode line drawing characters, such as Andale Mono or Lucida Console. (Unfortunately Vista’s gorgeous new Consolas font does not have those.)

Window → Translation:

Character set translation on received data:
Select UTF-8.
Adjust how PuTTY handles line drawing characters:
Select Use Unicode line drawing code points.

Connection → Data:

Terminal details: Terminal-type string:
Enter “linux”.

Now line drawing characters should show up as they are supposed to.

++

I also had do the following:
Terminal -> Features
check – Disable bidirectional text display

to get aptitude running correctly

cd /usr/local/directadmin/custombuild
./build update
perl -pi -e ‘s/clean_old_webapps=no/clean_old_webapps=yes/’ options.conf
./build clean
./build roundcube

Centos 5.2 kurmak ve duzenli guncellemek istedigim 1u bir serverim var.

Serverim Intel s5000vcl anakarti ile ustunde 6 Gb ecc registered buffeered ddr2 rame sahip

intel xeon 5310 quad core cpusu ile guclendirilmis durumda.

Bu anakart ustunde LSI1064e chipsetine sahip bir SAS kontrolcusu bulunmakta.

Yapmak istedigim Intelin kendi SAS Raid ini kullanarak 3×73 GB 15k Rpm Seagate SAS disklerimi RAID 0 olarak calistirmak.

Ancak nedense Intel inatla Centos / Redhat 5.2 icin bir turlu x86_64 driverlarini cikartmadi.

http://downloadcenter.intel.com u 1 ay boyunca hergun ziyaret etmeme ragmen bir cozum bulamamaktan sikayet ediyordum.

Sonra cozumun zaten uzun zamandir onumde durdugunu farkettim.

HOW TO / NASIL

1- Redhat / Centos 5.1 icin intelin cikardigi SAS driverlari indirilir.

ve centos 5.2 x86_64 kurulumu normal bir sekilde yapilir.

Boot ettikden sonra linux dd dememiz ve indirdigimiz driveri USB floppy imiz ile yuklememiz gerek.

Centos driver bulamadim falan desede Intel MEGASR yuklendi yazarsa ekranda isleme devam edilir.

2- Raid0 seklinde disklerimize default 5.1 kurulumu yapildikdan sonra

yum -y update ile sistem 5.2 ye terfi ettirilir.

3- Makinamiz reboot ettikten sonra – update sonrasi yukledigimiz degil  default 5.1 kernelimiz ile acmaliyiz –

Reboot dan sonra asagidaki adimlar yapilir

4-

megasr modulu yeni yerine kopyalanir – not kernel numaralari eskidir yenisine gore duzenleyin.

cp -r /lib/modules/2.6.18-8.el5/updates /lib/modules/2.6.18-8.1.15.el5/
Depmod calistirilir
depmod -a 2.6.18-8.1.15.el5
yeni bir boot imaji olusturulur.
update sonrasi gelen yeni img yi /boot altindan silip yeniden olusturuyoruz
mkinitrd /boot/initrd-2.6.18-8.1.15.el5.img 2.6.18-8.1.15.el5
Reboot ve yeni kernelimiz ile centos 5.2 miz calismaya hazir.
Gule gule kullaniniz.

Ayni seyi bu makina ustune kurmayi dusundugum hypervm ile openvz kernelindede deneyecegim az sonra.
Calisacagindan eminim...
Centos forumlarina tesekkurler :)

								

Create An Image
dd if=/dev/sda | gzip > /mnt/sdb1/sda.img.gz

Restore An Image
gzip -dc /mnt/sdb1/sda.img.gz | dd of=/dev/sda

Ben

Not: resim Teb.com.tr sitesinden alintidir. Tum haklari kendilerine aittir 🙂


if the message is frozen

exim -bpru|grep frozen|awk {'print $3'}|xargs exim -Mrm

if the message is <>

exim -bpru|grep '<>'|awk {'print $3'}|xargs exim -Mrm

if all

exim -bpru|awk {'print $3'}|xargs exim -Mrm