Clone a Virtual Machine from the shell (The Script)

After few comments on my previous blog related on how to manually clone a Virtual Machine from the shell I've decided to write a simple script to do everything automatically. Maybe this could be useful for newbies but basically it reproduces all the information reported on my latest blog.

There's no rocket science here and I've tried to keep the script simple and hackable for anyone, it required me some time (less than 1h) due to my poor sed knowledge, I've taken it as an exercise to improve my sed capabilities.

As in open source feel free to improve or modify it as you wish, send me an updated copy so I can publish your best version as well, error checking it's quite simple now. You may input absolute or relative paths but there're few limitations around.

Basic Usage:

VMCopy <old name> <new name>oldname is the name of the directory with original VMWare filesnewname is the name of the directory with newly created VMWare files

simple, isn't it ?

Here's the script:

#!/bin/bash## @name VMCopy - Copy/Clone a VMWARE Virtual machine with a new name## @author Andrea Benini (Ben)# @since 2011-02# @website http://www.linux.com# @email andrea benini (at domain name) gmail [DoT] com# @package Use it to get a physical copy of an existing machine, no snapshots or# VMWare tools involved in this operation, it's a plain text bash script# @require This tool should be portable to many UNIX platforms, it just requires:# sed, dirname, basename, md5sum, $RANDOM (shell variable) and few more# shell builtins commands## @license GPL v2 AND The Beer-ware License# See GPL details from http://www.gnu.org/licenses/gpl-2.0.html# "THE BEER-WARE LICENSE" (Revision 43)# Andrea Benini wrote this file. As long as you retain this notice you# can do whatever you want with this stuff. If you make modification on# the file please leave author notes on it, if you improve/alter/modify# it please send me an updated copy by email. If we meet some day, and# you think this stuff is worth it, you can buy me a beer in return.# Andrea Benini#SOURCEPATH=$(dirname "$1")TARGETPATH=$(dirname "$2")SOURCEMACHINE=$(basename "$1")TARGETMACHINE=$(basename "$2")