Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vmware esxi perl script for backup

Posted on 2012-03-20
16
Medium Priority
?
1,008 Views
Last Modified: 2012-04-04
Hello,

I am trying to use the perl script esxi-backup.pl to backup my unlicensed version of VMware ESXI 4.1.  I have one datastore with 2 VM's.  The second VM copys fine, but the first only copies a few bytes of the vmdk file which should be like 100GB.  I've attached the screen shot of what I see when the script runs.
Capture.JPG
0
Comment
Question by:Sean Rhudy
  • 8
  • 7
16 Comments
 

Author Comment

by:Sean Rhudy
ID: 37745652
#
# ESXi 3.5 Backup Script
#
# Autor: Christian Gruetzner
#
#
#############################################################################
#
#2008-08-22  V 1.0 Basic Script
#            Functions:     - create snapshots of all local VM's
#                           - get files from ESX-Datastore to local Store
#                           - exclude unneccessary files from backup
#                           - remove all created snapshots
#                           - actual time in log
#
#############################################################################




my $url = "https://dsesxi01/sdk/vimService";     #URL to your ESX Host
my $username = "root";                                  #Username
my $password = "Gp*4rVS71";                                    #User password
my $snapshotname = "BackupSnap";                        #Name of your Snapshot
my $DSPath = "[datastore1]";                            #Datastore name on ESX Host, example [datastore]
my @VMNames;
$VMNames[0] = "DSDC001";                      #Uncomment the next lines if you like to backup more vm's
$VMNames[1] = "DSAP01";
#$VMNames[2] = "";
#$VMNames[3] = "";
#$VMNames[4] = "";
#$VMNames[5] = "";
#$VMNames[6] = "";
#$VMNames[7] = "";
#$VMNames[8] = "";
#$VMNames[9] = "";
my $RCLIPath = "C:/Progra~1/vmware/VMware~1";           #VI Remote CLI Path (Windows: Use ONLY Short Folder Names!!!!)
my $DestPath = "Z:/";                                   #Destination Path you like to copy to (Windows: Use ONLY Short Folder Names!!!!)

#IMPORTANT!!! -- Under DestPath must exist the VMNames Folder 
#(For Example if your VMNames[0] = "ServerA" and your DestPath = "D:/": D:/ServerA/)
#--------------------------------------------------------
# For the short folder name use "dir /X"










#call the sub function (at the bottom)
&actualtime();
print " ***** Script Start *************************\n\n";

&actualtime();
print " ----- Create Snapshots of running VM's -----";
print "\n\n";
system("perl $RCLIPath/Perl/apps/vm/snapshotmanager.pl --url $url --username $username --password $password --operation create --powerstatus poweredOn --snapshotname $snapshotname");
print "\n\n";





&actualtime();
print " ----- Copy VM files to local storage   -----";
print "\n\n";
my $i = 0;
#special loop for arrays. run as long the array has data
foreach (@VMNames)
{
    #read all available files and save filenames in the cache-array
	my @cache = `perl $RCLIPath/bin/vifs.pl --url $url --username $username --password $password --dir \"$DSPath $VMNames[$i]\"`;
	#run as long the cache array has data and save the value everytime in $filename
	foreach my $filename (@cache)
	{
		#exclude uninterresting files from backup to save backup space
	 	if($filename !~ /.log/ && $filename !~ /.vswp/ && $filename !~ /.vmsn/ && $filename !~ /-delta/)
	 	{
	 		#remove the "\n" at the end of $filename to prevent a error massage in log
			chomp($filename)
			&actualtime();
			print " ----- Copy File: ";
	 		print $filename;
	 		#get files from VM Datastore to a local Storage
			system("perl $RCLIPath/bin/vifs.pl --url $url --username $username --password $password --get \"$DSPath $VMNames[$i]/$filename\" \"$DestPath$VMNames[$i]/$filename\"");
			print "\n";
		}
	}
	$i++;
}
print "\n\n";





&actualtime();
print " ----- Remove Snapshots of running VM's -----";
print "\n\n";
system("perl $RCLIPath/Perl/apps/vm/snapshotmanager.pl --url $url --username $username --password $password --operation remove --powerstatus poweredOn --snapshotname $snapshotname --children 1");
print "\n\n";

&actualtime();
print " ***** Script End ***************************";










#sub function to print the actual time in the log
sub actualtime
{
	my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
	    $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);
	my $CTIME_String = localtime(time);
	$Monat+=1;
	$Jahrestag+=1;
	$Monat = $Monat < 10 ? $Monat = "0".$Monat : $Monat;
	$Monatstag = $Monatstag < 10 ? $Monatstag = "0".$Monatstag : $Monatstag;
	$Stunden = $Stunden < 10 ? $Stunden = "0".$Stunden : $Stunden;
	$Minuten = $Minuten < 10 ? $Minuten = "0".$Minuten : $Minuten;
	$Sekunden = $Sekunden < 10 ? $Sekunden = "0".$Sekunden : $Sekunden;
	$Jahr+=1900;
	
	print "$Jahr-$Monat-$Monatstag $Stunden:$Minuten:$Sekunden";
}

Open in new window

0
 
LVL 3

Expert Comment

by:gorhon
ID: 37746104
ok, but why using vmware vcb backup? please find vcb installation on the web. not hard.
0
 
LVL 124
ID: 37746501
Why don't you use the tried and tested Ghetto VCB?

5. ghettoVCB

http://communities.vmware.com/docs/DOC-8760 ((Will work on FREE ESXi, no licensed required.)

(can be performed whilst the virtual machine is live or powered on)

Above taken from my EE Article


VMware ESX/ESXi Backup Guide
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:Sean Rhudy
ID: 37749750
vcb isn't free.  GhettoVCB looks much more difficult to configure and run.  The perl script was fairly simple to configure and is working for one VM, just not the other.  Any ideas on what's happening?
0
 
LVL 124

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE^2) earned 2000 total points
ID: 37749806
GhettoVCB is simple, supported, developed and maintained by the community.

The PERL script you've found is old and outdated, and developed for ESXi 3.5.
0
 

Author Comment

by:Sean Rhudy
ID: 37750880
Is there a more simple guide out there for GhettoVCB besides the one above?
0
 
LVL 124
ID: 37751994
You download the script and makes changes to the ghettoVCB.conf file.

The URL above is the best source of how to configire ghettoVCB.

If you are not comfortable with scripts, I would suggest  purchasing a $500 License from VMware and Veeam Backup and Replication v6.
0
 

Author Comment

by:Sean Rhudy
ID: 37764047
Sorry for the late response, let me give ghettoVCB a try.
0
 

Author Comment

by:Sean Rhudy
ID: 37777813
Ok, I am configuring Ghetto VCB and have a question.  I want to backup to a NAS drive.  I'm confused on the difference between:

VM_BACKUP_VOLUME=/vmfs/volumes/dlgCore-NFS-bigboi.VM-Backups/WILLIAM_BACKUPS

and

Defining the NFS information

Do I use one or the other?
0
 
LVL 124
ID: 37777840
specify the datastore you need to backup to

so I have a datastore called

/vmfs/volumes/nfs

i would use thatbin the config
0
 

Author Comment

by:Sean Rhudy
ID: 37777946
I don't want to backup to a datastore, I want to backup to a Network attached storage device. Can I do that?
0
 
LVL 124
ID: 37777967
yes, but needs to be added to the host server.

GhettoVCB can automatically mount and dismount the network attached storage, or you can attach to ESXi permenantly. network attached storage connected to ESX server is a datastore.

option is yours.
0
 

Author Comment

by:Sean Rhudy
ID: 37777995
Got ya, so would I connect the Nas device as a datastore prior to doing this, or will GhettoVCB do it for me?
0
 
LVL 124
ID: 37778011
youncan connect it advance, and leave it connected, or GhettoVCB will auto mount and demount.

choice is yours.
0
 
LVL 124
ID: 37778015
less configurationm and issues if you connect it.
0
 

Author Comment

by:Sean Rhudy
ID: 37808313
I have ghettoVCB setup but am having errors in the backups, I will open a new question.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Teach the user how to delpoy the vCenter Server Appliance and how to configure its network settings Deploy OVF: Open VM console and configure networking:
Teach the user how to rename, unmount, delete and upgrade VMFS datastores. Open vSphere Web Client: Rename VMFS and NFS datastores: Upgrade VMFS-3 volume to VMFS-5: Unmount VMFS datastore: Delete a VMFS datastore:

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question