Migrating OpenVZ VM

From Virtualizor Wiki
Jump to: navigation, search


This article will explain how to migrate your OpenVZ VMs on a Virtualizor Server to a new Virtualizor Server.

The vzmigrate utlity is used to migrate a container from one Hardware Node to another.

Note : This will lead to downtime for avoiding any kind of data lose.


Make sure:

  • you have at least one good backup of the virtual machine you intend to migrate
  • rsync is installed on the target host
  • In general you cannot migrate from bigger kernel versions to smaller ones


This method involves migrating the entire server to the new server including all VMs and the entire Virtualizor database.


  • [Old Server] : This indicates that the command/operation has to be executed on the old server.
  • [New Server] : This indicates that the command/operation has to be executed on the new server.

First set old server to authenticate the new server with the ssh keys

First we have to setup SSH to permit the [Old Server] to be able to login to the [New Server] without a password prompt. Run the following on the [Old Server].

  • Download the ssh key generation file and set executable permission to it
 wget http://mirror.softaculous.com/virtualizor/setsshkey.sh  
 Chmod +x setsshkey.sh 
  • Run the below command to set ssh keys on both the server
 ./setsshkey.sh [New Server ip][Port]
 It will prompt for [New Server] password .
  • Once you provide the password the keys will be automatically setup .You can test it by trying to connect from [Old Server] to [New Server] .

Importing the Database From old server server to new server

  • Create the dump of the old Virtualizor database [Old Server]
$ /usr/local/emps/bin/mysqldump -u root -p"MYSQL_ROOT_PASSWORD" virtualizor > /root/dump.sql

NOTE : You can find the MYSQL_ROOT_PASSWORD ($globals['dbpass']) in /usr/local/virtualizor/universal.php

  • Copy the dump to the New server [New Server]
$ scp root@OldServer_IP:/root/dump.sql /root/
  • Now login to the MySQL client utility [New Server]
$ /usr/local/emps/bin/mysql -u root -p"MYSQL_ROOT_PASSWORD"

NOTE : You can find the MYSQL_ROOT_PASSWORD ($globals['dbpass']) in /usr/local/virtualizor/universal.php

This will open the MySQL Client Utility.

  • Remove the virtualizor database and create the database again. [New Server]
$ mysql> DROP DATABASE virtualizor;
$ mysql> CREATE DATABASE virtualizor;

You can now exit the MySQL Client Utility by pressing Ctrl+C

  • Import the old server's database dump [New Server]
$ /usr/local/emps/bin/mysql -u root -p"MYSQL_ROOT_PASSWORD" virtualizor < /root/dump.sql

NOTE : You can find the MYSQL_ROOT_PASSWORD ($globals['dbpass']) in /usr/local/virtualizor/universal.php

Migrate all running containers

Here's a simple script to be executed on the [Old Server] that will migrate each container one after another. Just pass the destination host node ip as the single argument to the script:

  • Make a new file and name it migrate.sh
 touch migrate.sh
  • Copy the below content in the migrate.sh and save the file using any editor .
 for CT in $(vzlist -H -o veid); do vzmigrate -v --remove-area no --keep-dst $1 $CT; done
  • Change migrate.sh permission to executable .
 chmod +x migrate.sh
  • Execute the below script
./migrate.sh [New Server ip]

Assign the new IPs to the VMs via the Virtualizor interface [New Server] and copy templates

You will need to add the new IP Pool to the new Virtualizor Server (which you got with your new server).
Also copy all the old template from /vz/template/cache of old server to new server using scp .
scp /vz/template/cache/* root@newserverip:/vz/template/cache
Once you have added the IP Pool you can assign the new IPs to the VMs you had just migrated .

Reference link

For more reference you can Visit the below link :- https://openvz.org/Migration_from_one_HN_to_another


If you face any issues, please feel free to email us at support [at] virtualizor [dot] com