Thursday, April 16, 2009

How to schedule a GhettoVCB backup job or any other script you want

Hi folks, in order to schedule the GhettoVCB backup script you will need to use the program Plink.exe I spoke about in my previous post.

First download the Plink.exe program and place it in a folder on your server. I create a directory on the C drive called putty and place plink.exe in c:\putty. Then create a batch file using notepad called ghettoVCB.bat.

My batch file assumes the following things for the sake of this example:

  • The ESXi servers IP address is 192.168.1.5
  • The username is root to login
  • The root password is mypassword
  • backuplog.txt is the name of the text file where the output of the commands will be sent
Now edit the ghettoVCB.bat file and enter the following line on one line, I usually turn word wrap off in Notepad, substitute the values for your own values:

c:\putty\plink.exe root@192.168.1.5 -pw mypassword “nohup ./vmfs/volumes/datastore1/ghettoVCB.sh /vmfs/volumes/datastore1/vmwarebackups > /vmfs/volumes/datastore1/backuplog.txt &”

Create a windows scheduled task now and point it at the batch file and schedule it to run at whatever interval you like. You now have a scheduled backup job for ESXi!

-RP

23 comments:

Ken said...

First of all thanks for the info!

Plink is executing the script perfectly but the backuplog.txt is empty. It is creating the file but nothing is being written to it.

any ideas?

Ronald said...

it doesnt work for me :(

Piet said...

Thx for this great guide Raj! Only problem I'm left with is (as said above) the backuplog.txt. After the job finishes it's still 0 kb. The backuplog is being stored on the NFS location.

If you have any idea what might be wrong please share ;-)

@Ronald: what does not work exactly? Did you try executing the .bat in cmd to see what errors it generates?

Ronald said...

Hi Piet,

It just wont work for me. It wont create the backup at all.

I tried to run the batch file on cmd and it says "the system cannot find the path specified"

I just followed everything what Raj has instructed.

When i had that error, i put the .bat file and plink from where my CMD path is, and i tried to run it again and this time no error, i was able to generate the log file now, but the backup still wont show up on the backup drive or anywhere else.

I've been trying to figure this out for more than a week now.
Can you help please?

Piet said...

Hi Ronald,

There are 2 things you need to check:
-First: Try editing the bat file in the DOS editor ( when in cmd type "edit ghettoVCB.bat"
This way you can fix the characters/path that might have been altered when you typed them in notepad. I had this problem for example with my password and also the qoute (") characters in the command.

-Second: check the line where you specify the file that ghettoVCB.sh needs for the hosts. Because Raj posted in his previous posts that he used the name "vmbackups" as the hosts file the above line will not work (note that he uses "vmwarebackups"). This will result in the problem you posted above, only a backuplog.txt without any actual backups. So you need to edit the vmwarebackups to vmbackups (in case that this has not been changed yet).

If this works, please let us know if your backuplog is also 0 kb.

Ronald said...

Hi Piet,

I did change the host file to the host file that i created. It's all been changed according to my settings and still doesnt work.

I will try editing the bat file and see how it goes this time.

Thanks

Ronald said...

still doesnt work. I only get the log file with 0KB. I still cant backup. I've tried everything.

btw, on my bat file i omit c:\plink as the bat file is already located at the same path where my plink.exe is. so its only plink.exe root@...etc..

am i doing something wrong?

if i try to put c:\plink it says the command c:\plink is not recognised or soemthing

Piet said...

Hi Ronald,

That is odd. Mine works fine with: c:\putty\plink.exe (as described in the guide). I let it that way even though my bat file is also already located in the c:\putty folder.

Csabo2 said...

I'm getting "ash: (a divide sign): not found

obsidian said...

The backup and everything else runs great, backuplog.txt is empty. Ideas?

Wolfgang said...

same here, backup works but backuplog.txt is empty!

Deniz said...

Hi,

i'm also using the Ghetto script for my exsi back-ups, actually it runs great for 2 of the 11 server is have on the machine. problem is, that when i make script run via cron, everything seems fine until i check the folder where the back-up files should be. the folder only contains a .vmx file and not the vmdk file..

do you guys have any idea whats going wrong?

Daniel said...

Thanks for this great Howto. The backup is working fine, but the .txt is also empty. I also tried replacing the '&' for '| tee' with the same empty file.

It would seems like ghettoVCB or ESXi cannot write the output on a file...?

Daniel said...

I've done many tests and here are my conclusion:

- There is no way to save the result of the backup when using NOHUP. It normally create a NOHUP.OUT, but it seems like the file is not created when using PLINK (it is working fine if the command is run locally on ESXi).

- If there's a SHELL error (like a file not found), it will not display in the logfile.

You could alway replace the string to something like that if all the file are in the same directory:
(after 'mypassword', between quotes)
"cd /vmfs/volums/datastore1/ && ghettoVCB.sh vmwarebackups > backuplog.txt &"

Daniel said...

I forgot a dot...! ;)

"cd /vmfs/volums/datastore1/ && ./ghettoVCB.sh vmwarebackups > backuplog.txt &"

Blue Linq said...

This script is missing the list of VM's to backup. You need to run it like this:

c:\putty\plink.exe root@10.5.36.40 -pw mypassword "nohup /vmfs/volumes/datastore2/ghettoVCB4i.sh /vmfs/volumes/datastore2/list > /vmfs/volumes/datastore2/backuplog.txt &"

/vmfs/volumes/datastore2/list is the list of the VM's you want to backup otherwise it will not do anything.

Regards,

Paul Aviles

Michael said...

First: Thanks to William and Raj!
I tested the script and the Howto (good job!) on esxi 4.0 with a small UbuntuServerVM, backuped locally to another folder on the vmfs.
In the beginning I ran into the issues mentioned above.
Here is my version of the .bat-file, which produces a backup and a logfile:


C:\PuTTY\plink.exe root@10.11.12.13 -pw mypassword "cd /vmfs/volumes/datastore1/ && ./ghettoVCB4i.sh vmbackups.txt > ghettobackup.log &"

Thanks to Daniel too, that did the trick!
Regards, Michael

jpotgieter said...

Million Dollar Question:

How do you restore? Everyone is talking about backing up the files. But how do you restore a 70 gb partition in 2 hours or less with ghettovcb once you have the virtual machine files on a detached hard drive?

Cycloon said...

Million Dollar Answer!

In our case (backup over iSCSI) we have two strategies for recover:

1) Start the VMs on the ESXiServer over iSCSI. The VMs run a little bit slower, but you are immediatly back in business. At midnight ;-) you can copy the VMs to the new ESXiServer.

2) Copy the VMs from the backup-store to the store of the new ESXi-Server, if you have time for it.

The copy process over iSCSI takes only 90 minutes for 270GB in our case.

ESXi-Server: HP DL380G5 with 410GB SAS RAID5
BKP-Server: HP xw4600 with 1TB SATA nonRAID
LAN: 1Gbit LAN
iSCSI Target Server: Starwind Free Edition (iSCSI-Images up to 2TB)

VMC said...

Hi,
First: Thanks for the great scritp!!!

The script is working perfect for me.
But i have a problem scheduling the script.
If i run the batch file manually, it works fine. But if i schedule the script (Windows) it indicates in the Task Scheduler that it’s running, but nothing happens, and it keeps indicating that the script running till i stop it manually. Any idea?

VMC said...

Problem Solved. Permission issue.

Keith DeConto said...

Any idea why I would be getting the following error and how to correct it:

"Failed to lock the file (16392)"

I am trying to run the ghettoVCB.sh with the following parameters set:
POWER_VM_DOWN_BEFORE_BACKUP=1
ENABLE_HARD_POWER_OFF=1
ITER_TO_WAIT_SHUTDOWN=10

It will work when the machine is already off, but not when the VM is running. Any help would be GREATLY appreciated.

Sincerely,
Keith DeConto

zman said...

On the restore I used VeeamFastSCP and I was able to push a 95GB file in under 2 hours. Using Winscp it was going to take over 7 hours!

Post a Comment