Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/6f5d98d2603c9ab34388 to your computer and use it in GitHub Desktop.
Save mamemomonga/6f5d98d2603c9ab34388 to your computer and use it in GitHub Desktop.
VMware ESXi Tech Support Mode(SSH)で仮想マシンをクローンする
#!/bin/ash
# ESXi Tech Support Mode(SSH)で仮想マシンをクローンする。
# コピー先のディスクイメージはThin Provisioning
# 一つのディレクトリにまとまっている必要がある。
# 仮想マシンは /vmfs/volumes/以下に [DATASTORE]/[VM] という形で存在しているので
# データストア: DS1にあるVM1をDS2のVM2としてクローンする場合は
# clone_virtual_machine.sh "DS1/VM1" "DS2/VM2"
# と実行する。クローン後は上記の例のVM2の名前でIntentoryに登録される。
if [ -z $1 ]; then
echo " USAGE 'DATASTORE/SOURCE' 'DATASTORE/DESTINATION'"
exit
fi
SRCDIR=/vmfs/volumes/$1
DSTDIR=/vmfs/volumes/$2
VMX=
echo "***************************************"
echo " SOURCE: $SRCDIR"
echo " DESTINATION: $DSTDIR"
echo "***************************************"
mkdir "$DSTDIR"
IFS=$'\n$'
for i in `ls "$SRCDIR"`; do
if [ $i != ${i%.vmx} ]; then
VMX=$i
echo "VMX: $VMX"
fi
if [ $i != ${i%-flat.vmdk} ]; then
continue
fi
if [ $i != ${i%.vmdk} ]; then
vmkfstools -i "$SRCDIR/$i" "$DSTDIR/$i" -d thin
continue
fi
echo "COPY: $i"
cp -a "$SRCDIR/$i" "$DSTDIR/$i"
done
vim-cmd solo/registervm "$DSTDIR/$VMX" "`basename "$DSTDIR"`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment