Clone an OpenVZ VE

Upgrade system to clone
hn# vzctl start veid-to-clone
hn# vzctl enter veid-to-clone
ve# yum update
ve# exit
hn# vzctl stop veid-to-clone

Run clone script with required attributes
hn# ./clone.sh
Usage ./clone.sh old_id new_id new_ip

hn# ./clone.sh 1 123 192.168.1.123
Stopping ve1...
Unable to stop: container is not running
Copying configuration...
Cloneing ve1...
Updateing ve123 configuration...
Starting clone...
Starting container ...
Initializing quota ...
Container is mounted
Adding IP address(es): 192.168.1.123
Setting CPU units: 1000
Configure meminfo: 65536
Set hostname: ve123.example.com
File resolv.conf was modified
Container start in progress...
Starting origin ve...
Starting container ...
Container is mounted
Adding IP address(es): 192.168.1.1
Setting CPU units: 1000
Configure meminfo: 65536
Set hostname: ve1.example.com
File resolv.conf was modified
Container start in progress...
Done.

Be aware that the script automatically stops and starts the origin VE as well as the cloned VE. Clone bash script below

#! /bin/bash

if [ $# != 3 ]; then
echo "Usage $0 old_id new_id new_ip"
exit 0
fi

OLDVE=$1
NEWVE=$2
IP=$3

echo "Stopping ve$OLDVE..."
vzctl stop $OLDVE
echo "Copying configuration..."
mkdir /vz/root/$NEWVE
cp /etc/vz/conf/$OLDVE.conf /etc/vz/conf/$NEWVE.conf
mkdir /vz/private/$NEWVE
echo "Cloneing ve$OLDVE..."
pushd /vz/private/$OLDVE; tar c --numeric-owner * | tar x --numeric-owner -C /vz/private/$NEWVE; popd
echo "Updateing ve$NEWVE configuration..."
cat /etc/vz/conf/$OLDVE.conf | grep -v "IP_ADDRESS" | grep -v "HOSTNAME" > /etc/vz/conf/clone.conf
echo "IP_ADDRESS="$IP"" >> /etc/vz/conf/clone.conf
echo "HOSTNAME="ve$NEWVE.haite.ch"" >> /etc/vz/conf/clone.conf
mv /etc/vz/conf/clone.conf /etc/vz/conf/$NEWVE.conf
echo "Starting clone..."
vzctl start $NEWVE
echo "Starting origin ve..."
vzctl start $OLDVE
echo "Done."