Usage: ./ghettoClone.sh [-h SERVER] [-v VM_TO_CLONE] [-n NAMING_CONVENTION] [-s START] [-e END] [-f NAME_FILE] -d
Please quote your params if you dare to use spaces in your naming conventions!
Ensure this script is being executed on VMware VIMA and your ESX/ESXi hosts are 3.5u2+
OPTIONS:
-h ESX/ESXi 3.5+ Server IP or Hostname
-v VM to clone (VM display name)
-n Clone naming convention
-s Starting value
-e Ending value
-f File containg naming convention for VM clones (separate each name with newline)
-d Dry run, produces only text output of what would be executed based on input parameters
(e.g.)
./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -n "UCSB-CLONE-" -s 1 -e 10
./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -n "UCSB-CLONE-" -s 1 -e 10 -d
./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -f cloneInputFile.txt
./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -f cloneInputFile.txt -d
[vi-admin@vima-primp-industries ~]$ sudo vifp addserver olga.resnet.ucsb.edu
root@olga.resnet.ucsb.edu's password:
[vi-admin@vima-primp-industries ~]$
[vi-admin@vima-primp-industries ~]$ sudo vifp listservers
olga.resnet.ucsb.edu
himalaya.primp-industries.com
[vi-admin@vima-primp-industries ~]$ vifpinit olga.resnet.ucsb.edu
[vi-admin@vima-primp-industries ~]$ ./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -n "UCSB-RESNET-CLONE-" -s 1 -e 3 -d
Retrieving info from: olga.resnet.ucsb.edu ...
Selection Available space Maximum Capacity Type Name
1) 34.18 GB 124.75 GB VMFS dlgCore-FC-LUN200.Templates
2) 244.61 GB 255.25 GB VMFS olga-local-SAS.Storage
3) 91.58 GB 151.75 GB VMFS dlgCore-FC-LUN202.VMstorage2
4) 29.19 GB 152.75 GB VMFS dlgCore-FC-LUN203.VMstorage3
5) 53.29 GB 150.75 GB VMFS dlgCore-FC-LUN201.VMstorage1
6) exit
Please select a datastore in which the cloned virtual machines will be stored:
2
#################### DRY RUN MODE ####################
# Temp working directory: tmp_clone_2009-01-09_144356
# ESX Server to initiate clone: olga.resnet.ucsb.edu
# SOURCE VM: UCSB_TEST
# SOURCE VM PATH: [http://olga-local-SAS.Storage|http://olga-local-SAS.Storage] UCSB_TEST/UCSB_TEST.vmx
# SOURCE VM DIR: [http://olga-local-SAS.Storage|http://olga-local-SAS.Storage] UCSB_TEST
# SOURCE VM DATASTORE: [http://olga-local-SAS.Storage|http://olga-local-SAS.Storage]
# DESTINATION VM DATASTORE: [http://olga-local-SAS.Storage|http://olga-local-SAS.Storage]
# VMDK-[0]: ->UCSB_TEST_1.vmdk<-
# VMDK-[1]: ->UCSB_TEST.vmdk<-
# 2 valid VMDK(s) total
# Clone naming convention: UCSB-RESNET-CLONE-{1-3}
# 3 clone(s) to create
##################################################
Start time: Fri Jan 9 14:36:59 PST 2009
End time: Fri Jan 9 14:37:04 PST 2009
Duration : 5 Seconds
[vi-admin@vima-primp-industries ~]$ ./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB_TEST -n "UCSB-RESNET-CLONE-" -s 1 -e 3
Retrieving info from: olga.resnet.ucsb.edu ...
Selection Available space Maximum Capacity Type Name
1) 34.18 GB 124.75 GB VMFS dlgCore-FC-LUN200.Templates
2) 244.61 GB 255.25 GB VMFS olga-local-SAS.Storage
3) 91.57 GB 151.75 GB VMFS dlgCore-FC-LUN202.VMstorage2
4) 29.19 GB 152.75 GB VMFS dlgCore-FC-LUN203.VMstorage3
5) 53.29 GB 150.75 GB VMFS dlgCore-FC-LUN201.VMstorage1
6) exit
Please select a datastore in which the cloned virtual machines will be stored:
2
0% Complete! - Creating clone "UCSB-RESNET-CLONE-1" - 0/3 - Time elapsed: 5 Seconds
0% Complete! - Creating clone "UCSB-RESNET-CLONE-1" - 0/3 - Time elapsed: 31 Seconds
...
0% Complete! - Creating clone "UCSB-RESNET-CLONE-1" - 0/3 - Time elapsed: 6.67 Minutes
33% Complete! - Creating clone "UCSB-RESNET-CLONE-2" - 1/3 - Time elapsed: 6.77 Minutes
...
33% Complete! - Creating clone "UCSB-RESNET-CLONE-2" - 1/3 - Time elapsed: 13.43 Minutes
66% Complete! - Creating clone "UCSB-RESNET-CLONE-3" - 2/3 - Time elapsed: 13.52 Minutes
...
66% Complete! - Creating clone "UCSB-RESNET-CLONE-3" - 2/3 - Time elapsed: 20.45 Minutes
100% Complete! - Creating clone "UCSB-RESNET-CLONE-3" - 3/3 - Time elapsed: 20.53 Minutes
Start time: Fri Jan 9 14:48:23 PST 2009
End time: Fri Jan 9 15:08:56 PST 2009
Duration : 20.55 Minutes
[vi-admin@vima-primp-industries ~]$ cat toCloneList
ALima
AAmbrosio
MKerr
[vi-admin@vima-primp-industries ~]$ ./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB-ENGINEERING -f toCloneList -d
Retrieving info from: olga.resnet.ucsb.edu ...
Selection Available space Maximum Capacity Type Name
1) 52.83 GB 124.75 GB VMFS dlgCore-FC-LUN200.Templates
2) 244.61 GB 255.25 GB VMFS olga-local-SAS.Storage
3) 91.50 GB 151.75 GB VMFS dlgCore-FC-LUN202.VMstorage2
4) 29.19 GB 152.75 GB VMFS dlgCore-FC-LUN203.VMstorage3
5) 53.29 GB 150.75 GB VMFS dlgCore-FC-LUN201.VMstorage1
6) exit
Please select a datastore in which the cloned virtual machines will be stored:
3
#################### DRY RUN MODE ####################
# Temp working directory: tmp_clone_2009-01-09_151630
# ESX Server to initiate clone: olga.resnet.ucsb.edu
# SOURCE VM: UCSB-ENGINEERING
# SOURCE VM PATH: [http://dlgCore-FC-LUN200.Templates|http://dlgCore-FC-LUN200.Templates] UCSB-ENGINEERING/UCSB-ENGINEERING.vmx
# SOURCE VM DIR: [http://dlgCore-FC-LUN200.Templates|http://dlgCore-FC-LUN200.Templates] UCSB-ENGINEERING
# SOURCE VM DATASTORE: [http://dlgCore-FC-LUN200.Templates|http://dlgCore-FC-LUN200.Templates]
# DESTINATION VM DATASTORE: [http://dlgCore-FC-LUN202.VMstorage2|http://dlgCore-FC-LUN202.VMstorage2]
# VMDK-[0]: ->UCSB-ENGINEERING_1.vmdk<-
# VMDK-[1]: ->UCSB-ENGINEERING.vmdk<-
# 2 valid VMDK(s) total
# Clone naming convention: [ AAmbrosio ALima MKerr ]
# 3 clone(s) to create
##################################################
Start time: Fri Jan 9 15:16:36 PST 2009
End time: Fri Jan 9 15:16:41 PST 2009
Duration : 5 Seconds
[vi-admin@vima-primp-industries ~]$ ./ghettoClone.sh -h olga.resnet.ucsb.edu -v UCSB-ENGINEERING -f toCloneList
Retrieving info from: olga.resnet.ucsb.edu ...
Selection Available space Maximum Capacity Type Name
1) 52.83 GB 124.75 GB VMFS dlgCore-FC-LUN200.Templates
2) 244.61 GB 255.25 GB VMFS olga-local-SAS.Storage
3) 91.50 GB 151.75 GB VMFS dlgCore-FC-LUN202.VMstorage2
4) 29.19 GB 152.75 GB VMFS dlgCore-FC-LUN203.VMstorage3
5) 53.29 GB 150.75 GB VMFS dlgCore-FC-LUN201.VMstorage1
6) exit
Please select a datastore in which the cloned virtual machines will be stored:
3
0% Complete! - Creating clone "AAmbrosio" - 0/3 - Time elapsed: 10 Seconds
...
0% Complete! - Creating clone "AAmbrosio" - 0/3 - Time elapsed: 2.62 Minutes
33% Complete! - Creating clone "ALima" - 1/3 - Time elapsed: 2.70 Minutes
...
33% Complete! - Creating clone "ALima" - 1/3 - Time elapsed: 5.42 Minutes
66% Complete! - Creating clone "MKerr" - 2/3 - Time elapsed: 5.50 Minutes
...
66% Complete! - Creating clone "MKerr" - 2/3 - Time elapsed: 8.12 Minutes
100% Complete! - Creating clone "MKerr" - 3/3 - Time elapsed: 8.20 Minutes
Start time: Fri Jan 9 15:21:35 PST 2009
End time: Fri Jan 9 15:29:49 PST 2009
Duration : 8.23 Minutes
You can also do this connecting to the ESXi server using putty ( ssh ) just run the cp ( copy command )
Enable ssh on your esxi server ( unsupported )
http://www.vdi.co.nz/tag/esx4i/
I am using esx4i
putty in to your server
1. cd to your datastore.
2. Make a new directory for the clone VM: mkdir /vmfs/volumes/Data1/web2/
3. In your vsphereclient, make sure VM is powered off,
4. copy vm to new folder,
eg: cp /vmfs/volumes/Data1/web/* /vmfs/volumes/Data1/web2/
5. In client, browse datastore, to new vm , add to inventory
6. Start the new VM in the vshpere client, when asked confirm " I copied "
7. Start original VM to prove they are both working.
keep it simple.
Note, VMware ESXi 3.5u4 was just released and the internal API seems to have been fixed and VI API will have only read-only access when using the free licensed version of ESXi. This script will most likely not work on U4, please be advised if you're going to upgrade. I have not had a chance to verify but I believe this will be the case: http://tinyurl.com/cxayy6 U3 will continue to have this hole in the API to provide both read/write access to the VI API.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
http://twitter.com/lamw