Start-VBRZip

PowerShell script exchange

Start-VBRZip

Veeam Logoby jcwuerfl » Wed Sep 05, 2012 2:16 pm

Is there any more documentation on Start-VBRZip somewhere? Was starting to look at this and the get-help start-vbrzip doesn't have as much help as the other commands do right now. Managed to do start a backup with this but trying to understand what some of the other options are like OutVariable.

NAME
Start-VBRZip

SYNTAX

Start-VBRZip [-BackupRepository <CBackupRepository>] -Entity <IItem[]> [-Compression <Int32>] [-DisableQuiesce] [-RunAsync] [-Verbose]
[-Debug] [-ErrorAction <ActionPreference>] [-WarningAction <ActionPreference>] [-ErrorVariable <String>] [-WarningVariable <String>] [-
OutVariable <String>] [-OutBuffer <Int32>]

Start-VBRZip [-Folder <String>] -Entity <IItem[]> [-Compression <Int32>] [-DisableQuiesce] [-RunAsync] [-Verbose] [-Debug] [-ErrorActio
n <ActionPreference>] [-WarningAction <ActionPreference>] [-ErrorVariable <String>] [-WarningVariable <String>] [-OutVariable <String>]
[-OutBuffer <Int32>]


Example run:

Code: Select all
 $viServerObject = Get-VBRServer -Name virtualCenterServer.domain.com
 $viObject = Find-VBRViEntity -Server $viServerObject -Name "virtualMachineName"
 Start-VBRZip -Folder e:\temp -Entity $viObject


Which created:

e:\temp\Backup_virtualMachineName_2012-09-04T153652.vbk

So was looking to see if I can specify the output file name more. More just the vmName.vbk or something simple.
jcwuerfl
Enthusiast
 
Posts: 44
Liked: 3 times
Joined: Wed Jun 29, 2011 8:26 pm
Full Name: James

Re: Start-VBRZip

Veeam Logoby tsightler » Wed Sep 05, 2012 2:31 pm

"OutVariable" (or "-ov") is a common PowerShell parameter, I don't think it's special to Start-VBRZip. It's used to capture output from each step in a pipeline for easier debugging. See here for more details.

I think effectively the first 5 parameters are the only ones that are unique for Start-VBRZip and they are largely self explanatory.

I'd guess you could just use PowerShell to rename the file after it's done.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Start-VBRZip

Veeam Logoby jcwuerfl » Wed Sep 05, 2012 3:45 pm

Thanks for the info. They are somewhat explanatory. I was thinking about doing that myself but wanted to make sure it wasn't possible by itself. aka why re-invent the wheel.

The other one I have question on is Compression but guessing its :

0 - None
1 - Low
2 - Optimal
3 - Best

Since its an Int32 ?
jcwuerfl
Enthusiast
 
Posts: 44
Liked: 3 times
Joined: Wed Jun 29, 2011 8:26 pm
Full Name: James

Re: Start-VBRZip

Veeam Logoby Gostev » Wed Sep 12, 2012 3:21 pm

For version 6.1, the number are:
Code: Select all
0, "None"
4, "Low"
6, "Optimal"
9, "Best"

Note to future readers: compression levels may change in future versions.
Gostev
Veeam Software
 
Posts: 21390
Liked: 2349 times
Joined: Sun Jan 01, 2006 1:01 am
Location: Baar, Switzerland

Re: Start-VBRZip

Veeam Logoby jcwuerfl » Thu Sep 13, 2012 12:18 pm

Thanks! @Gostev for that info!
jcwuerfl
Enthusiast
 
Posts: 44
Liked: 3 times
Joined: Wed Jun 29, 2011 8:26 pm
Full Name: James

Re: Start-VBRZip

Veeam Logoby Andreas Neufert » Fri Nov 09, 2012 3:13 pm

I think the first question isn´t really answered.
Does someone know how to set the exact filename or read out the exact filename after the VeeamZIP?
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Start-VBRZip

Veeam Logoby Vitaliy S. » Mon Nov 12, 2012 1:59 pm

That's not possible, however you can use something like this to specify the file name you need for the VeeamZIP job:
Code: Select all
Rename-Item file_name.txt new_name.txt
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Start-VBRZip

Veeam Logoby marcseitz » Mon Nov 12, 2012 3:26 pm 2 people like this post

Hi Guys,

I've had the same problem not to know which File was generated by Start-VBRZip.

I've created a Script which would be called by the VMware Orchestrator and a "Invoke-Command". The Script returns the Filename which was created by VBRZip or the Returncode "FAILED".
Maybe it's useful for you to expand the script to move the File to another location or rename it...

What the Script is doing:
- Getting the vCenter-Object
- Getting the VM-Object
- Creating an MD5-Hash as Foldername
- Starting VBRZip using the MD5-Hash
- Extracting the Returncode of VBRZip
- Returning "FAILED" or the Filename

Code: Select all
###############
# Definitions #
###############
$vcenter = "<MYVCENTERNAME>"
$myRepository = "\\<MYSERVERNAME>\<MYFILESHARE>"
$logfile = "<MYLOGFILE.LOG>"

if ( $args.length -ne 1 )
{
   Write-Warning "Calling Script with Paramenter: <VMName>"
   exit
}

#Loads Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

# Mapping Argument to internal variable
$vmname         = $args[0]

$tmp_date = get-date -format o
$tmp_log = $tmp_date +" START VeeamZIP for VM: $vmname" >> $logfile

############### Getting VM-Object ###############

write-host "Getting vCenter-Server-Object"
$myVcenter      = Get-VBRserver | where {$_.Name -eq $vcenter}

$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Using vCenter $myVcenter" >> $logfile

write-host "Getting VM-Infos from vCenter"
$myVM      = Find-VBRViEntity -Server $myVcenter -Name $vmname
if($myVM.name -ne $vmname)
{
   $tmp_date = get-date -format o
   $tmp_log = $tmp_date +"  - VM not found in vCenter -  EXITING" >> $logfile
   return 99
}

$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Using VM-Entity $myVM" >> $logfile

$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Using VM-Object $myVM.Reference" >> $logfile



############### Creating MD5-Hash for FolderName ###############
$myString = get-date -format o
$cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];
$hashAlgorithm = new-object $cryptoServiceProvider
$hashByteArray = $hashAlgorithm.ComputeHash([Char[]]$myString);
$myMD5 = ""

foreach ($byte in $hashByteArray)
{
   $myMD5 += “{0:X2}” -f $byte
}

$myFolder = "$myRepository\$myMD5\"

$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Using Target-Folder "+ $myFolder >> $logfile

############### Starting VeeamZIP ###############

write-host "Starting VeeamZIP"
$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Starting VeeamZIP: Start-VBRZip -Folder"+ $myFolder +" -Entity "+ $myVM.Name >> $logfile

$myZip = Start-VBRZip -Folder $myFolder -Entity $myVM

$tmp_date = get-date -format o
$tmp_log = $tmp_date +"  - Finished VeeamZIP with Errorcode " + $myZip.Result >> $logfile

write-host $myFolder
write-host $myZip

############### Checking Result ###############

if(($myZip.Result -eq "Failed") -or $myZip.Result -eq "null")
{
   $myReturn = "FAILED"
}
else
{
   $myFile = Get-Childitem -Path $myFolder
   $myReturn = $myFile.FullName
}

############### Return Filename or Returncode "FAILED" ###############

return $myReturn


Feel free to use, modify and extend this Script!

Regards,
Marc
marcseitz
Influencer
 
Posts: 17
Liked: 5 times
Joined: Wed Apr 04, 2012 11:17 am
Full Name: Marc Seitz

Re: Start-VBRZip

Veeam Logoby Andreas Neufert » Mon Nov 12, 2012 3:35 pm

Thabk you for this great script!
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Start-VBRZip

Veeam Logoby mckenzieaj » Thu Dec 06, 2012 9:31 pm

Many many thanks for the code snippet above, it massively reduced my research time.

I am scheduling this on a windows 7 box to do nightly off site backups to rotating USB3 hard disk

The .cmd wrapper I am using is as follows (in case this is helpful to anyone that is unfamiliar with kicking off this script in powershell v2).

Code: Select all
@echo off
set logfile=c:\utils\BackupVMsToExternalDisk.log.txt

echo External VM Backup started %DATE% %TIME% > %logfile%

::: If this is a new external disk, make sure the backup folder exists
if exist e:\. if not exist e:\HDVMBackup\. md e:\HDVMBackup

::: clean up old backups.
if not exist E:\HDVMBackups\. echo Cannot find destination folder E:\HDVMBackups\. >> %logfile% && goto endit
del e:\hdvmbackups\*.* /s /q
for /D %%f in (e:\hdvmbackups\*.*) do rd %%f /s /q

::: Backup relevant VMs with powershell script.
powershell.exe -file c:\utils\veeamzip.ps1 server01 >>%logfile% 2>&1
powershell.exe -file c:\utils\veeamzip.ps1 server02 >>%logfile% 2>&1
powershell.exe -file c:\utils\veeamzip.ps1 server03 >>%logfile% 2>&1
powershell.exe -file c:\utils\veeamzip.ps1 server04 >>%logfile% 2>&1


echo External VM Backup finished %DATE% %TIME% >> %logfile%

:endit


In addition I moved to a simpler subfolder name in the PS script, where it matches the VM using the appropriate variable:

Code: Select all
$myFolder = "$myRepository\$vmname\"


Finally, I love the fact that Veeam emails the logs of these jobs automatically and you can do double click restores. That said, I am *very* surprised that the scheduling of veeamzip jobs is not a native function of the console... it feels like it is a piece that is "missing"
mckenzieaj
Influencer
 
Posts: 13
Liked: 1 time
Joined: Wed Dec 16, 2009 5:24 am
Full Name: Andrew McKenzie

Re: Start-VBRZip

Veeam Logoby nmatese » Wed Feb 27, 2013 9:22 pm

mckenzieaj, could you possibly post a sample of your veeamzip.ps1?
nmatese
Lurker
 
Posts: 1
Liked: never
Joined: Thu Sep 27, 2012 10:42 pm
Full Name: Nick Matese

Re: Start-VBRZip

Veeam Logoby v.Eremin » Thu Feb 28, 2013 11:17 am

Hi, Nick.

I wouldn’t think there is something special in that file.

In the ways I see it, it must be a piece of the code which is responsible for getting given VM from a server and VeeamZiping it to a specified hard disk; probably, something that has been mentioned already:

Code: Select all
asnp VeeamPssnapin
$VM = Get-VBRServer -name "Name of your ESXi/vCenter Server" | Find-VBRViEntity -name "Name of VM you’re willing to backup"
Start-VBRZip -folder “Your folder” -Entity $VM


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 969 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Start-VBRZip

Veeam Logoby jim3cantos » Mon Mar 11, 2013 7:05 pm

nmatese wrote:mckenzieaj, could you possibly post a sample of your veeamzip.ps1?


I think veeamzip.ps1 is the powersell script shared above by Marc because both scripts (cmd and ps1) work fine in combination. Thanks to the authors.
jim3cantos
Enthusiast
 
Posts: 43
Liked: 5 times
Joined: Tue Jan 08, 2013 6:14 pm
Location: Madrid, Spain
Full Name: José Ignacio Martín Jiménez

Re: Start-VBRZip

Veeam Logoby NYTECJ » Fri Jun 14, 2013 7:40 pm

Wanted to know if someone can help me. I am trying to use powershell to perform a VeeamZip for our servers. Needless to say writing scripts is not my area of expertise. This is our VM setup.
Two VM Servers and the instances names
192.168.0.1 ESXi 5.0
File
Mail
Web
Desktop01
Desktop02
Desktop03
Desktop04
Desktop05

192.168.0.2 ESXi 5.0
Blackberry
Citrix
DC
UserDesk1
UserDesk2
UserDesk3
UserDesk4

How can I run a VBRZip that only uses all servers except for UserDesk1, 2, 3, 4 and Desktop01, 02, 03, 04, 05? Any help is greatly appreciated.
NYTECJ
Novice
 
Posts: 4
Liked: never
Joined: Tue Nov 15, 2011 3:40 pm

Re: Start-VBRZip

Veeam Logoby v.Eremin » Mon Jun 17, 2013 10:47 am 1 person likes this post

Have these servers been added to VB&R console through vCenter or as stanalone hosts?

In case of vCenter, the following script should be used:

Code: Select all
asnp VeeamPSSnapin
$Server = Get-VBRServer -name "Name of your VC" | where {$_.type -eq "VC"}
$VMNames = "File", "Mail", "Web", "Blackberry", "Citrix", "DC"
$Entity = $Server | Find-VBRViEntity -name $VMNames
Start-VBRZip -folder "Name of a folder you're going to backup VMs to" -Entity $Entity


In case of standalone servers, the other one:

Code: Select all
asnp VeeamPSSnapin
$Server1 = Get-VBRServer -name "Name of a first server" | where {$_.type -eq "ESXi"}
$VMNames1 = "File", "Mail", "Web"
$Entity1 = $Server1 | Find-VBRViEntity -name $VMNames
$server2 = Get-VBRServer -name "Name of a second server" | where {$_.type -eq "ESXi"}
$VMNames2 = "Blackberry", "Citrix", "DC"
$Entity2 = $server2 | Find-VBRViEntity -name $VMNames2
$Entity = $Entity1 + $Entity2
Start-VBRZip -folder "Name of a folder you're going to backup VMs to" -Entity $Entity


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 969 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests