How to backup/restore vm from openvz in Centos 5.8


http://webserverpage.com/?p=237

This is in continuation of the link above.

[root@openvz ~]# vzlist -a
CTID      NPROC STATUS    IP_ADDR         HOSTNAME
101         12 running   192.168.2.127   subopenvz.com

Backup/Restore Openvz VMs with vzdump on CentOS

1. Download and install cstream as it is a depedency for vzdump.
http://pkgs.repoforge.org/cstream/

wget http://pkgs.repoforge.org/cstream/cstream-2.7.4-3.el6.rf.i686.rpm

rpm -Uvh cstream-2.7.4-3.el6.rf.i686.rpm

2. Download and install vzdump.

http://download.openvz.org/contrib/utils/vzdump/

wget http://download.openvz.org/contrib/utils/vzdump/vzdump-1.2-4.noarch.rpm

rpm -Uvh vzdump-1.2-4.noarch.rpm

1.2-6 version of vzdump, the location of the modules is not “automatic” so I need to export the location of the PVE libraries that vzdump requires

export PERL5LIB=/usr/share/perl5/

3. It is time to the backup process.

Checked your current VM veid first:

[root@openvz home]# vzlist -a
CTID      NPROC STATUS    IP_ADDR         HOSTNAME
101         12 running   192.168.2.127   subopenvz.com

4. Create a directory where you want to save the backup. Mine is /home/backup.

mkdir /home/backup

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

/************the result should look like this***********/
[root@openvz backup]# vzdump  –compress –dumpdir /home/backup –stop 101
INFO: starting new backup job: vzdump –compress –dumpdir /home/backup –stop 101
INFO: Starting Backup of VM 101 (openvz)
INFO: CTID 101 exist mounted running
INFO: status = CTID 101 exist mounted running
INFO: backup mode: stop
INFO: bandwidth limit: 10240 KB/s
INFO: stopping vm
INFO: Stopping container …
INFO: Container was stopped
INFO: Container is unmounted
INFO: creating archive ‘/home/backup/vzdump-openvz-101-2012_12_07-12_44_15.tgz’
INFO: Total bytes written: 545996800 (521MiB, 3.5MiB/s)
INFO: archive file size: 197MB
INFO: restarting vm
INFO: Dump file /vz/dump/Dump.101 exists, trying to restore from it
INFO: Restoring container …
INFO: Container is mounted
INFO:     undump…
INFO: Container restore failed (try to check kernel messages, e.g. “dmesg | tail”)
INFO: Error: undump failed: Invalid argument
INFO: Restoring failed:
INFO: Error: Unknown image version: 304. Can’t restore.
INFO: Starting container…
INFO: Adding IP address(es): 192.168.2.127
INFO: Setting CPU units: 1000
INFO: Container start in progress…
INFO: vm is online again after 166 seconds
INFO: Finished Backup of VM 101 (00:02:46)
INFO: Backup job finished successfuly
/*************end of results**************************/

So now you backup files will be located at this path.
[root@openvz backup]# ls
vzdump-openvz-101-2012_12_07-12_44_15.log  vzdump-openvz-101-2012_12_07-12_44_15.tgz

To Restore.
Let say the CTID 101 corrupt for some server issues then we can use vzrestore.

yum install vzrestore

cd /home/backup
vzrestore vzdump-openvz-101-yourfilename.tgz 101

Start the vz service to run the restored vm.

[root@openvz private]# service vz restart
Bringing down interface venet0:                            [  OK  ]
Stopping OpenVZ:                                           [  OK  ]
Starting OpenVZ:                                           [  OK  ]
Bringing up interface venet0:                              [  OK  ]
Starting CT 101:                                           [  OK  ]

To uninstall openvz and all the components.

1. To see the list of the packages related to vz.
[root@openvz backup]# rpm -qa | grep vz
vzctl-core-4.1-1
vzquota-3.1-1
vzdump-1.2-4
ovzkernel-2.6.18-308.8.2.el5.028stab101.1
vzkernel-2.6.32-042stab065.3
vzctl-4.1-1
vzkernel-firmware-2.6.32-042stab065.3
ovzkernel-2.6.18-53.1.6.el5.028stab053.6

2. Remove the packages.

[root@openvz backup]# rpm -e vzctl-core-4.1-1 vzquota-3.1-1 vzdump-1.2-4 ovzkernel-2.6.18-308.8.2.el5.028stab101.1 vzkernel-2.6.32-042stab065.3 vzctl-4.1-1 vzkernel-firmware-2.6.32-042stab065.3 ovzkernel-2.6.18-53.1.6.el5.028stab053.6


Leave a Reply