PowerShell script exchange
Post Reply
jcwuerfl
Enthusiast
Posts: 44
Liked: 4 times
Joined: Jun 29, 2011 8:26 pm
Full Name: James
Contact:

Start-VBRZip

Post by jcwuerfl »

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.
tsightler
VP, Product Management
Posts: 6009
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRZip

Post by tsightler »

"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.
jcwuerfl
Enthusiast
Posts: 44
Liked: 4 times
Joined: Jun 29, 2011 8:26 pm
Full Name: James
Contact:

Re: Start-VBRZip

Post by jcwuerfl »

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 ?
Gostev
Chief Product Officer
Posts: 31457
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Start-VBRZip

Post by Gostev »

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.
jcwuerfl
Enthusiast
Posts: 44
Liked: 4 times
Joined: Jun 29, 2011 8:26 pm
Full Name: James
Contact:

Re: Start-VBRZip

Post by jcwuerfl »

Thanks! @Gostev for that info!
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Start-VBRZip

Post by Andreas Neufert »

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?
Vitaliy S.
VP, Product Management
Posts: 27055
Liked: 2710 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Start-VBRZip

Post by Vitaliy S. »

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
marcseitz
Influencer
Posts: 18
Liked: 5 times
Joined: Apr 04, 2012 11:17 am
Full Name: Marc Seitz
Contact:

Re: Start-VBRZip

Post by marcseitz » 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
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Start-VBRZip

Post by Andreas Neufert »

Thabk you for this great script!
mckenzieaj
Influencer
Posts: 13
Liked: 1 time
Joined: Dec 16, 2009 5:24 am
Full Name: Andrew McKenzie
Contact:

Re: Start-VBRZip

Post by mckenzieaj »

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"
nmatese
Lurker
Posts: 1
Liked: never
Joined: Sep 27, 2012 10:42 pm
Full Name: Nick Matese
Contact:

Re: Start-VBRZip

Post by nmatese »

mckenzieaj, could you possibly post a sample of your veeamzip.ps1?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin »

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.
jim3cantos
Enthusiast
Posts: 59
Liked: 12 times
Joined: Jan 08, 2013 6:14 pm
Full Name: José Ignacio Martín Jiménez
Location: Madrid, Spain
Contact:

Re: Start-VBRZip

Post by jim3cantos »

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.
NYTECJ
Novice
Posts: 6
Liked: never
Joined: Nov 15, 2011 3:40 pm
Contact:

Re: Start-VBRZip

Post by NYTECJ »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin » 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.
NYTECJ
Novice
Posts: 6
Liked: never
Joined: Nov 15, 2011 3:40 pm
Contact:

Re: Start-VBRZip

Post by NYTECJ »

Great. :D That can work. Is there a switch that allows the system to create separate .vbk files for each server with compression?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin » 1 person likes this post

If you’re willing to get a seprate .vbk file for each VM, then you need to create a given number of different VeeamZIP jobs:

Code: Select all

asnp VeeamPSSnapin
$Server = Get-VBRServer -name "Name of your VC/ESX(i) host" | where {$_.type -eq "VC"}
$VMName = "Name of your VM”
$Entity = $Server | Find-VBRViEntity -name $VMName
Start-VBRZip -folder "Name of a folder you're going to backup VM to" -Entity $Entity  
You can choose different level of compression, using –compression parameter:

Code: Select all

Start-VBRZip -folder "Folder" -Compression *Number -Entity $Entity


*Number:

• 0 – None
• 4 – Dedupe-friendly
• 6 – Optimal (Recommended)
• 9 - Extreme


Hope this helps.
Thanks.
NYTECJ
Novice
Posts: 6
Liked: never
Joined: Nov 15, 2011 3:40 pm
Contact:

Re: Start-VBRZip

Post by NYTECJ »

That works. Thank you very much.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin »

You’re welcome. Should any additional help be needed, feel free to contact us. Thanks.
siddharth_k11
Lurker
Posts: 1
Liked: never
Joined: Apr 19, 2011 5:42 am
Full Name: Siddharth Kathe
Contact:

Re: Start-VBRZip

Post by siddharth_k11 »

Hi,

I am getting error in following script for taking backup of hyper-v vm

PS C:\Windows\system32> $Server = Get-VBRServer -name "Server01" | where {$_.type -eq "VC"}
PS C:\Windows\system32> $VMNames = "Test02"
PS C:\Windows\system32> Start-VBRZip -folder "D:\VeeamBKP" -Entity $Entity
Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Supply a non-null argument and try
the command again.
At line:1 char:41
+ Start-VBRZip -folder D:\VeeamBKP -Entity <<<< $Entity
+ CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Start-VBRZip

Post by ThomasMc »

Code: Select all

$Entity = $Server | Find-VBRViEntity -name $VMName
Missing this
greendx
Influencer
Posts: 13
Liked: never
Joined: May 18, 2011 2:06 pm
Full Name: Eugene Lipsky
Location: New York
Contact:

Re: Start-VBRZip

Post by greendx »

Is there a way to specify a sub-folder within a repository when using VBRZip to backup to a repository?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin »

In this case you should use -Folder parameter, instead of -Repository one. Thanks.
jim3cantos
Enthusiast
Posts: 59
Liked: 12 times
Joined: Jan 08, 2013 6:14 pm
Full Name: José Ignacio Martín Jiménez
Location: Madrid, Spain
Contact:

Re: Start-VBRZip

Post by jim3cantos »

Hello,

after diving for a while in the forums I just wanted to share a ps1 script that uses Start-VBRZip to backup some vm's to a repository and then import the backup generated to veeam server. It includes tips from several threads and first part is only for running Start-VBRZip commands as administrator and avoid permission errors. Just fill appropriately the parameters between <>. For example, <UNC path to backup directory> is the full UNC path to repository directory from veeam backup server. Probably it can be optimized so feel free to do it.

Code: Select all

# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
 
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
 
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
   {
   # We are running "as Administrator" - so change the title and background color to indicate this
   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
   $Host.UI.RawUI.BackgroundColor = "DarkBlue"
   clear-host
   }
else
   {
   # We are not running "as Administrator" - so relaunch as administrator
   
   # Create a new process object that starts PowerShell
   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
   
   # Specify the current script path and name as a parameter
   $newProcess.Arguments = $myInvocation.MyCommand.Definition;
   
   # Indicate that the process should be elevated
   $newProcess.Verb = "runas";
   
   # Start the new process
   [System.Diagnostics.Process]::Start($newProcess);
   
   # Exit from the current, unelevated, process
   exit
   }
 
# Run your code that needs to be elevated here
# Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
# Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = "In1Month"
Add-PSSnapin -Name VeeamPSSnapIn
$Repository = Get-VBRBackupRepository -Name "<repository name>"
$Server = Get-VBRServer -name "<VC server>" | where {$_.type -eq "VC"}
$VMNames = "<vmname1>", "<vmname2>", "<vmname3>"
$Entity = $Server | Find-VBRViEntity -name $VMNames
$myZip = Start-VBRZip -BackupRepository $Repository -AutoDelete $Retention -Entity $Entity
############### Checking Result ###############
if(($myZip.Result -eq "Failed") -or $myZip.Result -eq "null")
{
   $myReturn = "FAILED"
}
else
{
   $LastVBK = Get-ChildItem "<UNC path to backup directory>" | where {$_.Extension -eq ".vib" -or $_.Extension -eq ".vbk"} | Sort-Object creationtime -Descending | select -First 1
   Import-VBRBackup –Server '<repository server>' –FileName $LastVBK.fullname
   $myReturn = $LastVBK.fullname

}
############### Return Filename or Returncode "FAILED" ###############
return $myReturn
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Start-VBRZip

Post by Andreas Neufert »

Very cool,

thank you very much!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin »

Why do you need to import newly created VeeamZIP file to a backup server? You're writing to a backup server, doesn't the newly created file get imported automatically, when a repository rescan takes place? Thanks.
jim3cantos
Enthusiast
Posts: 59
Liked: 12 times
Joined: Jan 08, 2013 6:14 pm
Full Name: José Ignacio Martín Jiménez
Location: Madrid, Spain
Contact:

Re: Start-VBRZip

Post by jim3cantos »

v.Eremin wrote:Why do you need to import newly created VeeamZIP file to a backup server? You're writing to a backup server, doesn't the newly created file get imported automatically, when a repository rescan takes place? Thanks.
Nope. I have tried both from powershell and the console and individual .vbk files are not imported. Doesn't have to be a backup set of files from another backup job to be able to import with repository rescanning?...in other threads and also in the help pages it seems to say so:
You may need to import backups to Veeam Backup & Replication in the following situations:

▪The Veeam backup server has failed and you have restored it in a new location. You want to restore VM data from backups created by the Veeam backup server that has failed.
▪You want to restore VM data from backups created on other Veeam backup servers.
▪You want to restore VM data from backups on the backup repository that is not connected to Veeam Backup & Replication (for example, if you removed it earlier).
You want to restore VM data from VeeamZIP files created on your Veeam backup server or other Veeam backup servers.
http://helpcenter.veeam.com/backup/80/v ... ckups.html
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip

Post by veremin »

Yep, my bad. Backup files created by VeeamZIP don't have .vbm along with them, thus, cannot be imported automatically during repository rescan. So, the import portion of code is still required. Thanks.
Andreas Neufert
VP, Product Management
Posts: 6707
Liked: 1401 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Start-VBRZip

Post by Andreas Neufert »

Would be cool if we can add vbm file automaticall at one of the next versions.
This would also help to avoid problems when customers want to use Veeam-ZIP with Seeding
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests