#vzclone num_alum old_CTID base_new_CTID new_hostname old_IPNat new_IPNat maskNat new_interface new_vmbrName
directorioCopias=/var/lib/vz/copias/
num_alum=$1
old_CTID=$2
base_new_CTID=$3
new_hostname=$4
old_IPNat=$5
new_IPNat=$6
maskNat=$7
new_interface=$8
new_vmbrName=$9
new_CTID=`expr $num_alum + $base_new_CTID`
echo "Nuevo CTID: $new_CTID"
#9 options
if test $# -lt 9; then
echo "Error: Número de parametros ha de ser 9"
exit -1
fi
#Doing the copy and the restore
echo "¿Quieres realizar la copia de la máquina $old_CTID ? s / n"
read realizarCopia
if test $realizarCopia == s ; then
vzdump $old_CTID --compress gzip --dumpdir $directorioCopias
echo " ¿Quieres renombrar el fichero generado? s / n"
read respuesta
if test $respuesta == s ; then
echo "Introduce el nombre original del fichero a modificar"
read nombreOriginal
echo ""
echo "Introduce el nombre que desees para la copia"
read nombreCopia
mv $directorioCopias$nombreOriginal $directorioCopias$nombreCopia.tar.gz
echo ""
echo "Comprobación de copia"
ls -l $directorioCopias | grep $nombreCopia.tar.gz
echo ""
fi
fi
#IP control
if test $new_CTID -gt 254; then
echo "Error: La IP supera el rango 0 - 255"
exit -1
else
“”
echo “¿Que es lo que vas a clonar, CT o VM ¿”
echo “1. CT”
echo “2. VM”
read clonacion
if test $clonacion –lt 1 || test $clonacion –gt 2 then
echo “No has elegido una opción correcta, elige 1 o 2”
exit -1
fi
ipAsignarBridge="192.168.$new_CTID.1"
if test $clonacion == 1 ; then
echo "Nombre máquina de la cual quieres duplicar:"
read maquina
vzrestore $directorioCopias$maquina.tar.gz $new_CTID
else
qm clone $old_CTID $new_CTID --name $new_hostname --net0 e1000=,bridge=vmbr$new_CTID
fi
# vzctl set $new_CTID --hostname $new_hostname --save
# vzctl set $new_CTID --ipdel $old_IPNat --save
# vzctl set $new_CTID --ipadd $new_IPNat/$maskNat --save
vzctl set $new_CTID --netif_add $new_interface,,,,$ new_vmbrName --save --force #new veth in PROXMOX.
#Writing in /etc/network/interfaces for create switch
# echo "Escribiendo los nuevos datos del switch ..."
# echo "" >> /etc/network/interfaces
# echo "auto vmbr$new_CTID" >> /etc/network/interfaces
# echo "iface vmbr$new_CTID inet static" >> /etc/network/interfaces
# echo " address $ipAsignarBridge" >> /etc/network/interfaces
# echo " netmask 255.255.255.0" >> /etc/network/interfaces
# echo " bridge_ports eth0" >> /etc/network/interfaces
# echo " bridge_stp off" >> /etc/network/interfaces
# echo " bridge_fd 0" >> /etc/network/interfaces
# echo "Cambios guardados correctamente. Reiniciando red"
/etc/init.d/networking restart
fi
#ROUTING RULES
post-up iptables –A FORWARD –s ‘172.16.0.0/16’ –d ‘192.168.0.0/16’ –j REJECT
post-up iptables –t nat –A POSTROUTING –s ‘172.16.0.0/16’ –o vmbr0 –j MASQUERADE
post-down iptables –t nat –D POSTROUTING –s ‘172.16.0.0/16’ –o vmbr0 –j MASQUERADE
post-down iptables –D FORWARD –s ‘172.16.0.0/16’ –d ‘192.168.0.0/16’ –j REJECT