Who can help me (to understand how) to implement lamw's backup script (ghettoVCBni.sh page)? Even after a lot Googl'ing I don't know how to do this (..newbie..). I am currently running ESXi with 2 local datastores and would like to backup VM's from the first to the second. I suppose i have run the script on the ESXi host but can't find out how of where to do it. I would really appreciate if anyone would write a (small) howto.
Thanks in advance, Edmond
1) You need to enable access into the ESXi console.
Follow these instructions to do this: http://www.vm-help.com/esx/esx3i/ESXi_enable_SSH.php
2) Optional: If you mainly do work in Windows (if not skip to 3 ), open the ghettoVCBni.sh up in notepad (this is asuming you've already downloaded the script from http://communities.vmware.com/docs/DOC-8760) and change:
VM_BACKUP_VOLUME=/vmfs/volumes/kevin-test-nfs-storage
to reflect whatever datastore you want to store your backups in. In your case, this would be the name of your second local datastore. The datastore MUST have a /vmfs/volumes/ preceding it. Another option you should look at is how many previous backups you want to keep for each virtual machine. This can be edited on the line:
VM_BACKUP_ROTATION_COUNT=3
Warning: DO NOT PRESS RETURN AFTER ANY LINES INSIDE NOTEPAD AS THIS CAN POSSIBLY BREAK THE SCRIPT.
3) SCP the ghettoVCBni.sh file onto the ESXi server. You can use WinSCP (the username is root, the password is whatever management password you gave ESXi) to do this if you are running Windows, else, use the *nix scp command. (e.g. from the source run: scp ghettoVCBni.sh root@192.168.0.100: )
4) Either SSH into the ESXi server using "putty" or something or physically go (or use digital KVM or whatever) to the ESXi console itself and login as root.
5) Make a file on the ESXi server that lists the VMs that you want to backup.
There are two easy ways to do this:
A) Create the backup_vms file inside the ESXi console
If you know how to use a *nix text editing tool like vi then use it to make a text file that has all of the display names for the virtual machines that you want to back up. Remember that there is a new line for every virtual machine's display name.
If you don't know how to use any *nix text editing tools, the easiest (although tedious ) way to do this inside the ESXi console is:
echo VM1 > backup_vms
echo VM2 >> backup_vms
echo VM3 >> backup_vms
To check your work, run: cat backup_vms
the output should look like:
~ # cat backup_vms
VM1
VM2
VM3
~ #
If it doesn't, run: rm backup_vms and start over (hence, the tedious remark). Someone chime in if there's a way to do this without rm'ing it or editing it with vi.
B) Create the backup_vms file on a separate system and SCP it into the ESXi server. You have to be careful though, don't use notepad because after every return, it'll add in ^M (hence the warning up top). This is bad. Again, you can check your work using cat backup_vms inside the ESXi console (after you scp it over of course) to make sure there aren't any weird characters.
Remember, the virtual machines inside the backup_vms file MUST be registered on the ESXi host (i.e. existing in the ESXi host's inventory inside vi-client). Also, it would be easiest to have the ghettoVCBni.sh and backup_vms file to be in the same directory. For this document, it's assuming that you are in /. To make sure you are there, use pwd. To go there use: cd /
5) If you didn't follow the optional step 2 then edit the ghettoVCBni.sh script using a text editor inside the ESXi console and change:
VM_BACKUP_VOLUME=/vmfs/volumes/kevin-test-nfs-storage
to reflect whatever datastore you want to store your backups in. In your case, this would be the name of your second local datastore. The datastore MUST have a /vmfs/volumes/ preceding it. Another option you should look at is how many previous backups you want to keep for each virtual machine.
This can be edited on the line:
VM_BACKUP_ROTATION_COUNT= 3
6) Change permissions on script to allow execution: chmod +x ghettoVCBni.sh
7) Run the script. In this document's case: ghettoVCBni.sh backup_vms
8) Sit and wait or go do something else.
These instructions also apply to ESX ( minus step 1 ). Oh yeah, this script can be executed on live (powered on) virtual machines and you don't need any extra gimmicks to run it.
Have a good day,
Tuan
Just a quick FYI to the newer users of the *nix world: Step 8 should read: ./ghettoVCB.sh backup_vms (or ./ghettoVCBni.sh backup_vms)
Thanks to lamw for this great script, and tlduong for the how-to.
Thanks for taking the time to put together clear step by step instructions:
I have it working but it skips any VM that already have snapshots. How do I override this behavior?
I want to put the backups on an nfs mounted volume but the script just says
that a snapshot already exists and skips it.
Thanks!
thanks dspero.
nzmose, this was how the script was designed. It skips over virtual machines that have snapshots. I suppose this was done as a precautionary measure. If you need this functionality, you may have to modify the script and if so, I wouldn't know where to begin.
As tlduong has stated, this was per our design. Snapshots should not be kept for long duration, changes should be committed back in a timely fashion. When running backups I wanted to ensure that if you had snapshots, you would commit them before backing up, hence the script will notify you and just skip over the Virtual Machine. I suppose if you really need to keep the snapshots around, you would need to modify the script slightly to accommodate for the copying of the snapshot VMDK file, as of now it just looks for the "VMDK(s)" within the .vmx file and then provides that as input to the vmkfstools copy.
The problem with snapshots, is the snapshot file will be listed in the .vmx file and the original parent VMDK will not be listed. If you were to work around that and search the directory of the Virtual Machine directory, then you could run into the issue where the VMDK may be stored in another datastore, so it's sort of a complicated issue. You'll have to think about it a little if you're looking to modify the script, and if you know your environment, and you're storing everything with the VM, then you can assume certain things and change the script as it fits your environment.
We try to make it generic and script against possible issues that may occur but every environment will be different, so hopefully these ideas give you some direction on where to go with the script.
Thanks
Thanks for your detailed answer!
i try this script and it looks great, but i have some questions... for automation i use crond, but on reboot, esxi replace modified root's crond config with default, how can I prevent this? or have the opportunity to run script from unix server with crontab remotely via ssh?
in windows i can use plink.exe, any unix alternative?
Hey guys,
thanks for the detailed posts. I have one (hopefully only one) small glitch.
new esxi server, dummy VIMA install (trying to back it up instead of my live VMs)
windows 2003 with NFS under WSFU /DSsnaps is the share
i have both the .sh script and the machine defs file in the /DSsnaps share. It is set up in ESXi as well, and is accessible.
if i SSH into the ESXi and cd to the /vmfs/volumes/DSsnaps/ and run ghettoVCB.sh backup_vms
i get ghettoVCB.sh file not found.
-
should i be kicking this off from the windows box using plink?
hopefully this is a very small mistake. please let me know,
thanks,
-thomas
ive got the same problem, when you put the .sh script on the NFS share it's not executable.....
i changed also to 775 but same prob, if i move the .sh script to antoher path it works... anybody knows how to get it work from nfs share?