Solved

Vmware esxi perl script for backup

Posted on 2012-03-20
16
900 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:seanrhudy
  • 8
  • 7
16 Comments
 

Author Comment

by:seanrhudy
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 117
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
 

Author Comment

by:seanrhudy
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 117

Accepted Solution

by:
Andrew Hancock (VMware vExpert / EE MVE) earned 500 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:seanrhudy
ID: 37750880
Is there a more simple guide out there for GhettoVCB besides the one above?
0
 
LVL 117
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:seanrhudy
ID: 37764047
Sorry for the late response, let me give ghettoVCB a try.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:seanrhudy
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 117
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:seanrhudy
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 117
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:seanrhudy
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 117
ID: 37778011
youncan connect it advance, and leave it connected, or GhettoVCB will auto mount and demount.

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

Author Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Last article we focus in how to VMware: How to create and use VMs TAGs – Part 1 so before follow this article and perform the next tasks, you should read the first article how to create the TAG before using them in Veeam Backup Jobs.
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Teach the user how to install vSphere Update Manager  Console to Windows system:  Install vSphere Update Manager: Configure vSphere Update Manager plug-in in vSphere Client: Verify vSphere Update Manager settings in vSphere Client:
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now