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

Alibaba Cloud International 1GB RAM Singapore CN2 KVM VPS Review

Details: Alibaba Cloud International Edition: $4....

MySQL large capacity database backup method

It can be used on VPS and virtual hosts that supp...

Treudler 256MB RAM German KVM VPS Review

Details: Treudler: €9/year/256MB memory/5GB SSD s...

ZomboHost: $9.95/year/10GB space/100GB traffic/unlimited domain names

ZomboHost, a foreign hosting provider, was founde...

BlueVM: $9.9/year/512MB memory/20GB space/1000GB traffic/KVM

BlueVM has launched a great special offer package...

CorgiTech: $7/month/1GB RAM/30GB SSD/3TB bandwidth/VMware/Los Angeles/Phoenix

CorgiTech, a British hosting provider, is extreme...