Alternative script to clone VPS on OpenVZ

Silahkan di modifikasi sesuai kebutuhan pembaca

#!/bin/bash

## script name : vzclone.sh

OLDVE=$1
NEWVE=$2
vzctl stop $OLDVE
mkdir /vz/root/$NEWVE
echo “copying……”
cp /etc/vz/conf/$OLDVE.conf /etc/vz/conf/$NEWVE.conf
cp -a /vz/private/$OLDVE /vz/private/$NEWVE
echo “Starting old VPS …”
vzctl start $OLDVE;

echo -n “Start new VPS ? [Y/n] : ”
read opsi

if [[ -nz $opsi ]]; then
if [ $opsi == “Y”  ]; then
vzctl start $NEWVE;

##== change hostname
CurHostname=`vzlist -a | grep $OLDVE | tr -s ‘ ‘ | cut -d” ” -f6`
tmpHostname=$CurHostname”_clone”

echo -n “New VPS Hostname ? [ “$CurHostname”_clone ] : ”
read NewHostname
if [ -nz $NewHostname ]; then
vzctl set $NEWVE –hostname $NewHostname –save
else
vzctl set $NEWVE –hostname $tmpHostname –save
fi
##== chane hostname

fi
fi
NewIP=””
echo -n “New VPS IP Address? [Empty] : ”
read NewIP

CurIP=`vzlist -a | grep $OLDVE | tr -s ‘ ‘ | cut -d” ” -f5`
if [ $CurIP != ‘-‘ ]; then
vzctl set $NEWVE –ipdel $CurIP –save
fi

if [[ -nz $NewIP ]]; then
vzctl set $NEWVE –ipadd $NewIP –save
fi

echo “done.”

Cara menjalankan script:

# ./vzclone  [Old VPS ID]  [New VPS ID]

Contoh :

# ./vzclone  999 1005

Semoga bermanfaat

~ oleh r420r pada Oktober 3, 2008.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: