vz-clone: a nifty script to clone vz containers

The title says it all …

#!/bin/bash
# script to clone an openvz VE

set -e

if [ -z "$2" ]; then
    echo “Usage: $0 <veid> <new-id>”
    exit 1
fi

cfg=”/etc/vz/conf/$1.conf”
newcfg=”/etc/vz/conf/$2.conf”

if [ ! -e $cfg ]; then
    echo $cfg not found!
    exit 1
fi

VEID=$1
. $cfg
veprivate=”$VE_PRIVATE”

VEID=$2
. $cfg
newveprivate=”$VE_PRIVATE”

if [ -e $newcfg ]; then
    echo $newcfg already exists!
    exit 1
fi

if [ -e $newveprivate ]; then
    echo $newveprivate already exists!
    exit 1
fi

if vzlist | fgrep -w -q $1
then
    vzctl stop $1
fi

echo “Cloning $cfg to $newcfg”
cp -a $cfg $newcfg

echo “Cloning $veprivate to $newveprivate”
mkdir -p $newveprivate
cd $veprivate
tar cf – . | (cd $newveprivate && tar xf -)

echo “Do not forget to edit $newcfg (you need to edit at least HOSTNAME and IP_ADDRESS)”
echo “Also do not forget to make an alias”

Source – http://www.howtoforge.com/some-tips-on-openvz-deployment

Advertisement

About C S Shyam Sundar

I'm a thief; I am the will of independence; I am the power of persona; I am the creation of my environment; I am the pursuit of more; I know this, because I thrive on intelligence.

Posted on May 25, 2010, in thoughtpad and tagged , , , . Bookmark the permalink. Leave a Comment.

Leave a Reply

Please log in using one of these methods to post your comment:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.