Backing up and restoring an OpenVZ VPS using vzdump

Backing up and restoring an OpenVZ VPS using vzdump

Preparation

Now, let's assume that there are two OpenVZ hens, both of which are OpenVZ virtualization environments, and now we need to back up and transfer the VPS from Hen A to Hen B.
A server IP: 192.168.0.100
Server B IP: 192.168.0.101
Let's assume that both servers are running CentOS 6. In fact, there are no problems with other operating system versions.
First we need to install vzdump and rsync on both servers.

yum install vzdump rsync

Creating a mirror backup

This operation is only performed on server A. First, we use vzlist -a to view the currently running VPS list. Assuming that we want to back up a VPS with VEID 102, execute:

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

  • --compress means that the backup will be saved in compressed form, i.e. tgz format.
  • --dumpdir specifies where the backup files are saved. If not specified, the default is /vz/dump or /var/lib/vz/dump (depending on the operating system and version).
  • --stop stops the VPS before backing it up and restarts it after the backup is complete.

The corresponding output should be 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#

After the backup is complete, you can check the directory of the backup file:

ls -l /vz/dump/

You will 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:~#

Now we will use the scp command to migrate the backed up VEID 102 VPS to server B (from /vz/dump/vzdump-102.tgz on server A to /home on server B)

scp /vz/dump/vzdump-102.tgz [email protected]:/home

Restoring a VPS Backup

This operation only needs to be completed on server B. Execute the following command:

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

  • 250 is the new VEID of the VPS on server B. You can replace it with any value. Of course, for convenience, you can also directly use the original 102 as the VEID.

Because the VPS has been migrated, the assigned IP may change. Assuming 192.168.0.102 is its original IP, we now want to assign it a new IP 192.168.0.250 . Execute:

vzctl set 250 –ipdel 192.168.0.102 –save

Delete the original IP first, then add the new IP:

vzctl set 250 –ipadd 192.168.0.250 –save

If you need to change the hostname, execute:

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

Finally, start the VPS and the migration is complete:

vzctl start 250

via: http://dearroy.com/

<<:  Ramhost KVM VPS latest 6.7 this offer

>>:  Orbitservers: $11/year/128MB RAM/8GB/125G bandwidth/OpenVZ

Recommend

PulseHeberg: €3/month/2GB RAM/20GB storage/unlimited traffic/OpenVZ/Germany

PulseHeberg, founded in 2012, is a French hosting...

HostUS: $10/year/1 CPU/768MB memory/20GB space/2000GB/1 IP/OpenVZ

HostUS is a very stable host with good reviews, l...

My Custom Hosting: $18/year/2 cores/512MB/10G SSD/4TB bandwidth/KVM

My Custom Hosting, which I have introduced twice ...

How to optimize ads to increase click-through rate

3.1 Advertising Format: Beautify Your Advertiseme...

VaporNode: $7/month/2GB RAM/25GB SSD space/2TB bandwidth/OpenVZ/Tampa

VaporNode, an American hosting provider, was foun...

Cyanode: $2.5/month/512MB RAM/15GB SSD space/500GB bandwidth/KVM/Los Angeles

Cyanode, a newly established hosting provider, is...