VMware ovftool. Script VM for export.
Script body:
#!/bin/bash
#
#
# ~/scripts/export-vm.sh
#
#
#
_ovftool=$(which ovftool)
_source=""
_name=""
_format=""
_dest="/mnt/512/deliver"
ddate=$(date +%Y-%m-%d-%H_%M)
usage() {
cat << EOF
usage:
usage: $0 options
This script run.
OPTIONS:
-h Show this message
-s Source VM
-n Name of VM archive
-f For OVF VM archive: OVA or OVF
-v Verbose
EOF
}
mess() {
length=40
printf -v line '%*s' "$length"
echo ${line// /-}
echo -e "INFO::\t$1"
}
while getopts ":h:s:n:f:sno:" opt; do
case $opt in
s)
_source=$OPTARG
;;
n)
_name=$OPTARG
_name="${_name}_VMware"
;;
f)
_format=$OPTARG
;;
esac
done
if [[ -z $_source ]] || [[ -z $_name ]]
then
usage
exit 1
else
if [[ -z $_format ]] ;
then
_format="ovf"
fi
_dest="${_dest}/${_name}/${_name}_${ddate}"
_ddest="${_dest}/unarch"
mess " "
mess "Starting ..."
mess "Target is '${_source}'"
mess "Name of new vm is '${_name}'"
mess "Destination is '${_dest}'"
mkdir -pv ${_dest}
mess " "
_dest="${_dest}/${_name}.${_format}"
${_ovftool} ${_source} ${_dest} && mess "Finished..." || mess "ERROR:: Check input data"
# ${_dest} --compress 9 && mess "Finished..." || mess "ERROR:: Check input data"
#echo "_source=$_source , _name=$_name, _format= $_format, _dest=$_dest"
mkdir -pv ${_ddest}
${_ovftool} ${_dest} ${_ddest}
fi
Script body:
#!/bin/bash
#
#
# ~/scripts/export-vm.sh
#
#
#
_ovftool=$(which ovftool)
_source=""
_name=""
_format=""
_dest="/mnt/512/deliver"
ddate=$(date +%Y-%m-%d-%H_%M)
usage() {
cat << EOF
usage:
usage: $0 options
This script run.
OPTIONS:
-h Show this message
-s Source VM
-n Name of VM archive
-f For OVF VM archive: OVA or OVF
-v Verbose
EOF
}
mess() {
length=40
printf -v line '%*s' "$length"
echo ${line// /-}
echo -e "INFO::\t$1"
}
while getopts ":h:s:n:f:sno:" opt; do
case $opt in
s)
_source=$OPTARG
;;
n)
_name=$OPTARG
_name="${_name}_VMware"
;;
f)
_format=$OPTARG
;;
esac
done
if [[ -z $_source ]] || [[ -z $_name ]]
then
usage
exit 1
else
if [[ -z $_format ]] ;
then
_format="ovf"
fi
_dest="${_dest}/${_name}/${_name}_${ddate}"
_ddest="${_dest}/unarch"
mess " "
mess "Starting ..."
mess "Target is '${_source}'"
mess "Name of new vm is '${_name}'"
mess "Destination is '${_dest}'"
mkdir -pv ${_dest}
mess " "
_dest="${_dest}/${_name}.${_format}"
${_ovftool} ${_source} ${_dest} && mess "Finished..." || mess "ERROR:: Check input data"
# ${_dest} --compress 9 && mess "Finished..." || mess "ERROR:: Check input data"
#echo "_source=$_source , _name=$_name, _format= $_format, _dest=$_dest"
mkdir -pv ${_ddest}
${_ovftool} ${_dest} ${_ddest}
fi
Коментарі