Commit 153ecd6f authored by Danil Mikhailov's avatar Danil Mikhailov

create-vz-template added

parent 24d5f54f
#!/bin/bash
# Создание vz template из контейнера
VZDIR="/var/lib/vz"
VZPRIVATEDIR="$VZDIR/private"
TEMPLATEDIR="$VZDIR/template/cache"
SCRIPTNAME="$(basename $0)"
VERBOSE="true"
RETVAL=1
archive_vz(){
vzid="$1"
diskdesc="${VZPRIVATEDIR}/${vzid}/root.hdd/DiskDescriptor.xml"
# Если есть второй аргумент, то это имя template
if ! [ -n "$2" ] ; then
templatename="${vzid}".tar.gz
else
templatename="${2}".tar.gz
fi
# Монтируем если используется ploop
if [ -e "$diskdesc" ] ; then
mountdir="/mnt/${vzid}"
mkdir -p ${mountdir}
mount -t ploop "$diskdesc" ${mountdir} && \
tar --numeric-owner -czf "${TEMPLATEDIR}/${templatename}" -C "${mountdir}/" .
else
tar --numeric-owner -czf "${TEMPLATEDIR}/${templatename}" -C "${VZPRIVATEDIR}/$vzid/" .
fi
RETVAL="$?"
}
my_getopts(){
if ! [ -n "$1" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then
help
return 1
fi
archive_vz $@ && my_exit "Template from $vzid created: ${TEMPLATEDIR}/${templatename}" || my_exit "Error! Template not created."
}
help(){
example=etersoft-p8-20160527-systemd-x86_64
echo "$SCRIPTNAME <vz container id> [template name]"
echo "Create vz template from vz container."
echo ""
echo "Example: # ./${SCRIPTNAME} 800 $example"
echo "Creates template from 800 container and copy it to $TEMPLATEDIR/$example".tar.gz
my_exit
}
my_exit(){
$VERBOSE && echo "$1"
exit $RETVAL
}
my_getopts $@
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment