VMware
1 ... 11 12 13 14 15 ... 31 Previous Next 453 Replies Last post: Sep 30, 2009 8:55 AM by cincinnerdi   Go to original post

Re: Free ESXi Backup Solution for Windows

180. Nov 25, 2008 9:18 PM in response to: alusrc
Click to view Dave.Mishchenko's profile Guru 8,974 posts since
Nov 15, 2005
oem.tgz along with the other tgz files are extracted during the initial Loading VMware Hypervisor screen so it'l long before crond is started.

Re: Free ESXi Backup Solution for Windows

181. Nov 26, 2008 12:21 AM in response to: blueivy
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
The script has now been updated to allow the names of the Virtual Machines to contain spaces:

http://communities.vmware.com/docs/DOC-8760

Hopefully you'll start to use dashes and underscores in the future and refrain from adding spaces into filenames/directories.

Re: Free ESXi Backup Solution for Windows

182. Nov 26, 2008 3:35 AM in response to: lamw
Click to view JoSte's profile Novice 6 posts since
Nov 20, 2008
I have found one bug and some enhancement ideas.

I think in the new script this line:
 for VM_NAME in `cat ${VM_INPUT} | sed '/^$/d' | sed -e 's/^[ \t]*//;s/[ \t]*$//'`;  


Should be:
 for VM_NAME in `cat ${VM_INPUT} | sed '/^$/d' | sed -e 's/^[:blank:]*//;s/[:blank:]*$//'`;  	


Else you are going to just remove any "t","\" or spaces at beginning or end.

While at that, maybe this lines:
VMX_DIR=`echo ${VMX_CONF%.vmx}`     
VMX_DIR=`echo ${VMX_DIR%/*}`


Could be combined to:
VMX_DIR=`echo ${VMX_CONF%/*.vmx}` 	

At least in my tests it produced the same output that way ...

Then all
grep -E "${VM_NAME}" /tmp/vms_list | ...

should be changed to:
grep -E \"${VM_NAME}\" /tmp/vms_list | ...

So that the " is part of the search pattern. Else if input file contains 'test', it would also match for VMs that are called 'test1' or 'test vm' or anything else containing that word. Now that we have the " in the vms_list we should take benefit from it :-)

Regarding the crontab:
I think it should be enough to do a
mkdir /etc/rc.early.d


and then create a script file in it:
echo 'echo "01 05 * * 1-5 /opt/Backup/ghettoVCBni.sh  /opt/Backup/VMs2Backup" >>/var/spool/cron/crontabs/root' > /etc/rc.early.d/AddBackup2Crontab.sh
chown root:root /etc/rc.early.d/AddBackup2Crontab.sh
chmod 774 /etc/rc.early.d/AddBackup2Crontab.sh


I still need to test this, but I would think this should work.

-JoeSt

Re: Free ESXi Backup Solution for Windows

183. Nov 26, 2008 4:41 AM in response to: lamw
Click to view kpc's profile Enthusiast 98 posts since
Jul 12, 2006

Hi William

Is there any special reason why there needs to be an input file that contains the display names of the VM's you want to back up? I tried your first version of the script and I'm sure it didn't do this (could have dreamt it :-) however the new one seems to require this, is it becuase of the spaces in display names fix?

Good work on the script though...

Re: Free ESXi Backup Solution for Windows

184. Nov 26, 2008 5:28 AM in response to: lamw
Click to view carpenike's profile Enthusiast 40 posts since
Aug 3, 2006

Hello,

I'm wondering how difficult it would be to add a line to the script that copies week old backups to a different location prior to deleting them? Say I want to keep 7 backups and take one of those off-site per week and automate it all. What I could see doing is have the script copy the file that is 7 days old to an external hard drive and then delete it.

Thanks,

Ryan

Re: Free ESXi Backup Solution for Windows

185. Nov 26, 2008 6:14 AM in response to: JoSte
Click to view alusrc's profile Novice 20 posts since
Nov 24, 2008
lamw,

So adding a crontab to oem.tgz works like a charm. Didn't have to start crond like Dave mentioned, and the backups ran. However, when the jobs ran last night, I got a message for one of my VMs:

"Cannot open the disk '<location of disk on my host>.vmdk' or one of the snapshot disks it depends on. Reason: Device or resource busy."

Then,

"Failed to reopen disk '(null)'"

Then,

"Error encountered while restarting virtual machine after taking snapshot. The virtual machine will be powered off."

The VM just stayed off and we have to power it back on manually. Do you have any idea why that happened?

Re: Free ESXi Backup Solution for Windows

186. Nov 26, 2008 8:16 AM in response to: JoSte
Click to view alusrc's profile Novice 20 posts since
Nov 24, 2008

Should we be able to mount these vmdk files with the VMWare DiskMount utility? I'm trying to figure out if I can eliminate file level restores by just mounting the disk files and pulling data rather than turning the machine on through another host or something similar. I get an error using the VMWare utility.

Re: Free ESXi Backup Solution for Windows

187. Nov 26, 2008 8:58 AM in response to: kpc
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
kpc,

Both version 1 and 2 of the script has always worked in that fashion. You would feed in a list of the Virtual Machines you would like backed up and they're queried and backed up. How else would you do it ;)

The reason for the display name, which I think most user's have both the display name and the actual name of their directory/etc all match up, is that VMware allows you to have a different display name than the actual directory and possibly some of the other attributes. The queries that are return by using either "vmware-cmd -l" or "vmware-vim-cmd vmsvc/getallvms" show only display name

Hopefully this answered your question.

Re: Free ESXi Backup Solution for Windows

188. Nov 26, 2008 9:01 AM in response to: carpenike
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
It would not be too hard, but you'll have to modify this for your use case. You can set the rotation variable to go back at least 7 iterations and instead of "rm -rf" that backup, you could specify a new variable at the top and have it copy that off to say NFS datastore #2 and that can be used to be shipped offsite, then purge from that current backup datastore so you don't keep a duplicated copy unless that is you goal.

good luck

Re: Free ESXi Backup Solution for Windows

189. Nov 26, 2008 9:03 AM in response to: alusrc
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
great to hear.

Did you use v1 or v2 of the script? Usually when it says it can't open the disk, the snapshot has not been taking and there is till a VMFS lock on the master VMDK you're trying to access. You'll usually get promoted with device or resource busy. Not sure about the second set of messages and what was done afterwords. Have you tried to run a backup on this VM before? Perhaps try to run a manual backup or run the script only on this VM and see if you run into any odd results.

Re: Free ESXi Backup Solution for Windows

190. Nov 26, 2008 9:44 AM in response to: lamw
Click to view depping's profile Champion 2,997 posts since
Jan 17, 2005
lamw, great script. I wrote a short article to refer people to the solution you created:
http://www.yellow-bricks.com/2008/11/26/backup-your-esxi-vms/

Duncan
Blogging: http://www.yellow-bricks.com

If you find this information useful, please award points for "correct" or "helpful".

Re: Free ESXi Backup Solution for Windows

191. Nov 26, 2008 9:56 AM in response to: JoSte
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
Hi JoSte,

Thanks for your feedback,

I've uploaded a small test script to answer some of your questions regarding section 1 (disagree, you'll see from sample what I mean)

and

section 2 (agree that the test script works, but for some reason when enabling the devel mode to print out the variables, there is discrepancy and I need to do more testing before making that change). I try to think of all the possible use cases where an end user could be providing bad input, say "spaces" in their names and try to take into account. The sed command that I had setup works as expected.

I agree with your section 3, I must have missed that and yes it would not do an exact match. I've modified the code but have not updated the doc, I'll do that later today.

Let me know if you have any questions regarding the "test.sh"
Attachments:

Re: Free ESXi Backup Solution for Windows

192. Nov 26, 2008 9:57 AM in response to: depping
Click to view lamw's profile Champion 2,814 posts since
Nov 27, 2007
Thank's Duncan, very honored.

Love your blog by the way.

Re: Free ESXi Backup Solution for Windows

193. Nov 26, 2008 11:04 AM in response to: JoSte
Click to view aremmes's profile Enthusiast 22 posts since
Sep 10, 2008
JoSte wrote:
I think in the new script this line:
 for VM_NAME in `cat ${VM_INPUT} | sed '/^$/d' | sed -e 's/^[ \t]*//;s/[ \t]*$//'`;  

Should be:
 for VM_NAME in `cat ${VM_INPUT} | sed '/^$/d' | sed -e 's/^[:blank:]*//;s/[:blank:]*$//'`;  	

Else you are going to just remove any "t","\" or spaces at beginning or end.
"\t" is the tab character, so it'd remove either spaces or tabs. Also, your sed command wouldn't work; you'd need to recode it as:
for VM_NAME in `cat "${VM_INPUT}" | sed '/^$/d' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//'`

Or:
cat "${VM_INPUT}" | sed '/^$/d' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//' | while read VM_NAME;

Note the quotes around ${VM_INPUT}; without them, any spaces in the variable would break the script (the shell would see them as argument separators).

While at that, maybe this lines:
VMX_DIR=`echo ${VMX_CONF%.vmx}`     
VMX_DIR=`echo ${VMX_DIR%/*}`

Could be combined to:
VMX_DIR=`echo ${VMX_CONF%/*.vmx}` 	

At least in my tests it produced the same output that way ...
'dirname' was intended for that specific purpose:
VMX_DIR=`dirname "${VMX_CONF}"`

The quotes ensure that spaces in the path are passed to the command correctly.

Then all
grep -E "${VM_NAME}" /tmp/vms_list | ...

should be changed to:
grep -E \"${VM_NAME}\" /tmp/vms_list | ...

So that the " is part of the search pattern. Else if input file contains 'test', it would also match for VMs that are called 'test1' or 'test vm' or anything else containing that word. Now that we have the " in the vms_list we should take benefit from it :-)
Preferably you'd use word boundaries in the regular expression so that you're not forced to have quotes in the VM names:
grep -E "\<${VM_NAME}\>" /tmp/vms_list | ...

That way, if $VM_NAME == 'test', it won't match 'tests', 'test1', 'newtest', etc.

Re: Free ESXi Backup Solution for Windows

194. Nov 26, 2008 12:06 PM in response to: aremmes
Click to view JoSte's profile Novice 6 posts since
Nov 20, 2008
@lamw,
I have tested with your demo script. This are my findings:
# cat > /tmp/bad_input_file << __BAD_INPUT__
 Monitoring & Maintenance

 RESNET-UCSB


 blah2


    blah1

   blah2

 t

         tvm

                         tt

 __BAD_INPUT__
~ # IFS=$'\n'
~ # for VM_NAME in `cat /tmp/bad_input_file | sed '/^$/d' | sed -e 's/^[ \t]*//;s/[ \t]*$//'`;
 do
 echo "#$VM_NAME#"
 done
#Monitoring & Maintenance#
#RESNET-UCSB#
#blah2#
#blah1#
#blah2#
#vm#
~ #


So the sed on my ESXi does not interpret \t as tab. It just removes the t...
However this corrected version from aremmes works as I would expect it.
 # for VM_NAME in `cat /tmp/bad_input_file | sed '/^$/d' | sed -e 's/^[[:blank:]]*//;s/[[:blank:]]*$//'`
 do
 echo "#$VM_NAME#"
 done
#Monitoring & Maintenance#
#RESNET-UCSB#
#blah2#
#blah1#
#blah2#
#t#
#tvm#
#tt#
~ #

Preferably you'd use word boundaries in the regular expression so that you're not forced to have quotes in the VM names:
grep -E "\<${VM_NAME}\>" /tmp/vms_list | ...

That way, if $VM_NAME == 'test', it won't match 'tests', 'test1', 'newtest', etc.
I am by no means an expert in this, but what if there is a VM_NAME == 'test vm' and 'test'. Wouldn't that 'test' also match the 'test vm', then?
~ # grep -E "\<test\>" /tmp/vms_list
"16";"test vm";"[datastore-1]";"New Virtual Machine/New Virtual Machine.vmx"
~ # grep -E "\<test vm\>" /tmp/vms_list
"16";"test vm";"[datastore-1]";"New Virtual Machine/New Virtual Machine.vmx"
~ #

How about this:
grep -E "\"${VM_NAME}\"" /tmp/vms_list | ...

It should work also with spaces in $VM_NAME.
~ # grep -E "\"test vm\"" /tmp/vms_list
"16";"test vm";"[datastore-1]";"New Virtual Machine/New Virtual Machine.vmx"
~ # grep -E "\"test\"" /tmp/vms_list
~ #


About the VMX_DIR
~ # VMX_CONF=/vmfs/volumes/himalaya-local-SAS.VMStorage/RESNET-UCSB/RESNET-UCSB.vmx
~ # VMX_DIR=`echo ${VMX_CONF%.vmx}`
~ # VMX_DIR=`echo ${VMX_DIR%/*}`
~ # echo "Output: $VMX_DIR"
Output: /vmfs/volumes/himalaya-local-SAS.VMStorage/RESNET-UCSB
~ # VMX_DIR=""
~ # VMX_DIR=`echo ${VMX_CONF%/*.vmx}`
~ # echo "Output: $VMX_DIR"
Output: /vmfs/volumes/himalaya-local-SAS.VMStorage/RESNET-UCSB
~ #

So on my ESXi it is doing the same in both versions. However the suggested
VMX_DIR=`dirname "${VMX_CONF}"`

is anyway the better idea.

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities