Cloning a container in OpenVZ is a great way to backup your server before making any changes. If something goes wrong, you can easily turn on the cloned container and have your server back to where you started.

In this example, the old container will be CT111, and the new cloned container will be CT555. The first thing we need to do is stop the old container.

vzctl stop 111

Now it’s time to make the root directory for the new cloned container.

mkdir /vz/root/555

Copy the configuration file from old container to the new container.

cp /etc/vz/conf/111.conf /etc/vz/conf/555.conf

Make the private directory for the new cloned container.

mkdir /vz/private/555

The next command may take awhile depending on how much data you have stored. This will compress, copy, then uncompress all of the data to the new container.

pushd /vz/private/111; tar c --numeric-owner * | tar x --numeric-owner -C /vz/private/555; popd

You can now start the old container, or the new container. You can not have both containers running at the same time unless you change one of the IP addresses.

vzctl start 111

If you have onboot="yes" for CT555 (the powered off container) in your /etc/vz/conf/555.conf file, you should probably change it to onboot="no".

Resources

OpenVZ – Cloning VE

Pin It on Pinterest

Share This