Next, you have to download the following software for use on your computer to help you get this all accomplished.
- Putty.exe (This is one of the more famous SSH programs out there used to connect to the ESXi server via SSH)
- Plink.exe (This is used to run command line commands in your SSH session with the ESX server, this is integral for scheduling scripts)
- WinSCP (This program is used to upload and download files between your ESXi server and your workstation)
After you have downloaded these programs, please install them on your workstation. Then you can go and download the ghettoVCB.sh script from the VMware communities web site where this script is hosted at.
After you have downloaded the script, do not edit it on a Windows computer otherwise you run the risk of introducing control characters into the script which will cause the script to fail when run on the ESXi server. Instead, just upload the script to your ESXi server using WinSCP. Please ensure that you change the transfer settings mode to text mode for the transfer.
After you have transferred the script up to the ESXi server please ensure you move the script into your /vmfs/volumes/Datastore1 directory. There is a good reason for this. If you do not move it into your datastore directory the script will be erased the next time you reboot the ESXi server. The ESXi server will not erase anything stored in the VMFS datastore however. Your datastore might have a different name than mine so just make sure you put it in your datastore that you created when you installed ESXi.
After you have copied the script to this folder, create a new text file named whatever you want that contains a list of the virtual machine names as they are listed in your VMware client when you connect to your server. For example if you have three servers DC01, DC02, EXCHANGE01, then put those three names in the data file. You can create a data file in ESXi by doing the following, I am going to use the filename vmbackups for my example. First change directory to your datastore volume before creating the file. Keep in mind that everything is case sensitive.
- Type the following at the command prompt in your ESXi ssh session:
- cd /vmfs/volumes/Datastore1
- Type in: vi vmbackups
- Hit the insert key to enter editing mode in vi. Type in DC01, hit enter, type in DC02 hit enter, type in EXCHANGE01, and hit enter.
- Hit escape to exit editing mode.
- Type in a colon “:” and then type wq and hit enter, this will save the file and quit back to the command prompt.
There, now you have created your data file that contains the names of your virtual servers. Remember that this is case sensitive so if you typed in dc01 and your server’s actual name in the VMware client list is DC01 then it won’t work when the script runs.
Now you need to choose a location to store your backups too. You could just save your backups to your datastore and then manually use WinSCP to save them off everyday. Or you can mount an NFS share and have your backups save to that NFS location. The best way to do this is to install Windows Services for Unix version 3.5. Please follow the directions here on how to do this.
If you don’t have a Windows server with storage available for this then you could use a Windows workstation with a 3rd party NFS product to share out a drive. My own personal favourite is Allegro NFS. I am currently trialing the software and will probably purchase it for use in my test lab at home. I use it on my Vista machine at home where I have a USB external hard drive attached to it. Allegro NFS allows me to share out a folder on my USB drive and make it available to my ESX server. I have created a folder called vmwarebackups and shared it out using NFS. The NFS pathname is /x/vmwarebackups. Let’s say for example that my computer’s IP address is 192.168.2.10. Now what I need to do is connect to the ESXi server with my VMware client and add new storage.
- Do the following:
- Go to the configuration tab in the VMware client after highlighting your ESXi server. Click on the storage link under Hardware. Then click on the add storage link.
- Select Network File System from the options presented to you and click next
- In the Server field type in the IP address of the server that is hosting the NFS share, in my example it would be 192.168.2.10
- In the folder field type in the NFS folder name. With most products the folder naming convention will be the drive letter first and then the share name. If you are using Windows Services for Unix it will probably just be the share name. On my Vista machine my external drive is the X drive and the share is VMware backups. So the NFS path is /x/vmwarebackups and that is what I would type in this field. If I was on a Windows 2003 server using Windows Services for Unix and shared out the same share the path would just be /vmwarebackups and then that’s what I would type into the field
- Type in a name for the datastore, you can call it whatever you want. For example I will name it backup and then click next. Do not select the mount NFS As read only option.
- Then finish off the wizard by clicking finish and you’re done. You will now notice you have a new piece of storage called backup listed under storage.
- You can now test to see if the path exists by changing directory to it in an SSH session. Type in cd /vmfs/volumes/backup and that should switch you into that directory. Then try and create a file in that directory or make a new directory with the mkdir test command and it should create a folder for you called test. If this works, then this verifies for you that you have write access to this share.
Now you need to edit the script and change the options to suit your tastes. The way you edit the script is as follows:
Edit ghettoVCB.sh by typing in vi ghettoVCB.sh while you’re in the directory where you moved ghettoVCB.sh
Edit the following lines in the script, the script is nicely commented to let you know how to set up the parameters
- VM_BACKUP_VOLUME=/vmfs/volumes/backup (this is the path of your NFS share)
- ENABLE_2GB_SPARSE=0 (set this to 1 if you want to split your VMDK into 2 GB files)
- VM_BACKUP_ROTATION_COUNT=3 (Number of backups you want to keep before it deletes old ones)
- VM_BACKUP_DIR_NAMING_CONVENTION (I just leave this as is, it’s fine the way the default is setup)
- POWER_VM_DOWN_BEFORE_BACKUP=0 (I change this to 0 so I can do a live backup without shutting down the virtual server)
- ENABLE_HARD_POWER_OFF=0 (I change this to 0 to disable hard power offs)
- ITER_TO_WAIT_SHUTDOWN=4 (I leave this as is, it’s not applicable in our case since we’re not using hard power offs)
After setting this all up then you can save the ghettoVCB.sh script file and now you’re ready to run it. From the ghettoVCB.sh directory type in: ./ghettoVCB.sh vmbackups (this will run the script with the input file list of your virtual machines) and the backup will run and present to you a percentage progress counter as it backs up your virtual machines. You will notice that the counter will count fairly slow. Backing up to NFS is never a quick thing so keep that in mind and have patience.
The script will fail if you made any errors in the input file in regards to case sensitivity and it will also fail if there are any errors with the way you mounted your NFS share. In a future blog I will cover how to properly configure Windows services fo Unix to mount an NFS share.
You will remember that I asked you to download plink.exe previously. This is what you will use to create a Windows scheduled task that will log into the server and execute the ghettoVCB.sh script. In my next blog entry I will show you how to create this scheduled task.
-RP

22 comments:
every time I try it I "Error: Failed to extract VM_ID"
it can't reach that vm (it's on local disk of a different vm server) or it's vm id is named different that you have in your vmwarebackup text file
Thanks for the instructions, very helpful.
I am running into an issue when trying to run the script. When running the ./ghettoVCB.sh vmbackups, I am getting the error Permission denied.
I have mounted the share and am able to create a folder from the SSH connection onto the share.
I have added the line VM_BACKUP_VOLUME=/vmfs/volumes/External to the ghettoVCB.sh file. That path works when I type cd /vmfs/volumes/External.
Any suggestions on why I am running into a permission level issue? On the NFS server I am allowing all users and all machines to connect.
2Kyle:
Issue the
# chmod 755 ghettoVCB4i.sh to make the sh file executable.
Hi
This script is great but I'm running into an issue when the script tries to rename the lowest level directory from the date +%F format to ad the --1 on the end. The mv command is failing with:
mv: cannot rename /vmfs/volumes/VMBackupsNFS/VM-NAME/VM-NAME-2009-08-26: Input/output error.
I've looked at the script and echo'd out the $NEW variable which is what it uses to rename. I've run the script again and copied and pasted the command on the command line and it works!
I don't understand why it runs from the command line and not from the script.
I'm running the script as root with ./ghettoVCB.sh vmlist
If it were a permissions problem I'd expect it to fail from the command line too.
Any ideas please?
Sorry, in my previous post I meant to say my version is ESXi, 4.0.0, 181792.
Thanks,
Bryn.
I am getting:
"Snapshot found for vm1, backup will not take place"
10Q: I have VMs that have snapshots. I want to back these things up but the script doesn’t let me do it. How do I fix that?
10A: VM snapshots are not meant to be kept for long durations. When backing up a VM that contains a snapshot, you should ensure all snapshots have been committed prior to running a backup. No exceptions will be made…ever.
Searching how to consolidate the snapshots.
From the ghettoVCB page at VMware communities:
http://communities.vmware.com/docs/DOC-8760
10Q: I have VMs that have snapshots. I want to back these things up but the script doesn’t let me do it. How do I fix that?
10A: VM snapshots are not meant to be kept for long durations. When backing up a VM that contains a snapshot, you should ensure all snapshots have been committed prior to running a backup. No exceptions will be made…ever.
Can anyone shed any light on my posting of 26th August 2009 please? I'm still unable to use it.
I'm not sure I completely understand your problem Bryn. But, if the script isn't working, did you chmod the script file?
chmod +x ghettoVCB.sh
Hi Ted, thanks for replying. I'm not sure how else to put what I'm getting but I'll try. Basically when I run the script it errors with:
mv: cannot rename /vmfs/volumes/VMBackupsNFS/VM-NAME/VM-NAME-2009-08-26: Input/output error.
I've looked at the script and it's the line that try's to rename (using mv) the diretory to add a --1 on the end.
When I run the mv command from the command line it works! Logged in as the same user I run the script as.
Any ideas would be much appreciated.
Hope I've explained it a bit better this time.
Thanks.
Bryn
Running script get me that "Snapshot found for vm-dc03, backup will not take place"
And this is happening for all of my machines, I am not making any snapshots manually, but inside folder for vm-dc03 there are files named VM-DC03-000001-delta.vmdk
VM-DC03-000001.vmdk
VM-DC03-000002-delta.vmdk
VM-DC03-000002.vmdk
I have never created this files, this files are leftowers from the script which run for a bit. but after couple of days will not run. So when i issue command: #servicess.sh restart it will show up in vSphere Client in Snapshoot Manager as : Consolidate Helper -0.
How can I fix this, so delta files are removed at the end of the backup.
T.K
Hi, I have started nfs serwer on ubuntu and it is very good and free to use. for me it works fine. This blog helped me very much. Thx Raj
As T said, I get the same message after executing the ghettovcb script:
Snapshot found for VM_RHE52, backup will not take place
Start time: Fri Dec 11 00:05:17 WIT 2009
End time: Fri Dec 11 00:05:17 WIT 2009
Duration : 0 Seconds
Completed backing up specified Virtual Machines!
I can not found the backup file on directory destination as like I wrote on ghettoVCB.sh script.
Any idea for this issue?
Thank you
i can't get this ghettoVCB.sh to run on my esx4 Std server. I get a : command not founde 6: (and again at every blank line in the script, then the last two errors are line 88: syntax error near unexpected token '{
help please..
Hi There,
Does anyone there does know how to remove the ^M on the script?
naominahum
I don't know if ESX has the dos2unix command or not but that will do it for you if it does.
Otherwise you could use a global search and replace in vi.
Bryn,
Thanks for the quick response, but i had executed :%s/^M//g that command in vi but there still no luck. I dunno why it is not working in vmware.
Thanks in advance
Hello Sir,
I'm a new user of VMware, I'm using VMware ESXi 4.0 as Server Host and I access it in Windows using VMware vSphere Client. I want to have a script that will be placed in the server that will poweroff all the VMs then shutdown the host server? Can you help me with the script? Thanks. - Syd
The script will not back-up the VMs and will not shutdown via UPS. It will just execute the script residing on the ESXi 4.0 for a specific time and the ESXi server host will poweroff the VMs and then shutdown the machine. A very big thanks in advance.
Post a Comment