echo ""
echo "This script will guide You thru OpenVZ VPS ostemplate change/rebuild/reinstall process.
Script will never do any data erase without providing warning and asking for confirmation."
echo ""
vzlist -a
echo ""
echo "Enter VPS ID to work with:"
read ctid
echo ""
ls /vz/template/cache
echo ""
echo "Enter OStemplate name (see above) that you want to apply/use on a VPS $ctid. do NOT add .tar.gz at the end. Proper example form: centos-6-x86_64"
read tname
echo ""
echo "You selected following VPS to be reinstalled or OStemplate changed:"
vzlist -a | grep $ctid
echo ""
echo "WARNING: reinstall/OStemplate change will cause all VPS data be deleted permanently !!!!!!!!!"
echo "Do you really want all data on above mentioned VPS deleted and OS template $tname applied on it? (y = yes (delete data, reinstall), n = no (exit))"
read action
if [ "$action" == "y" ];then
vzctl stop $ctid
cp -p /etc/vz/conf/$ctid.conf /etc/vz/conf/$ctid.conf_bckp
echo "Was an .conf file coppied or there was an error? If there was an error, do Ctrl+C keyb. shortcut to quit this script.
If no /"cp/" error, then hit any key to continue:"
read qwertz
vzctl destroy $ctid
vzctl create $ctid --ostemplate $tname
echo ""
echo "Now please hit /"y/" key and Enter key to use old VPS config file - to rewrite new config by old VPS config"
echo "mv /etc/vz/conf/$ctid.conf_bckp /etc/vz/conf/$ctid.conf"
vzctl start $ctid
echo ""
echo "VPS $ctid should be running now and have new operating system $tname."
vzlist -a | grep $ctid
echo ""
echo "You may want to update an OSTEMPLATE variable in VPS config file /etc/vz/conf/$ctid.conf
New value is: $tname"
elif [ "$action" != "y" ];then
echo "You did not used Y key, so the script exited."
exit
fi
Bookmarks