PowerShell script exchange
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Correct, all vSphere cmdlets start with Vi prefix, while Hyper-V ones with HV. Thanks.
toriol
Lurker
Posts: 1
Liked: never
Joined: Jun 18, 2018 2:58 pm
Full Name: Leonardo Torio
Contact:

[MERGED] Feature Request - Schedule VeeamZIP

Post by toriol »

I recently was asked to take a clone of our production MySQL cluster and restore it in our lab. Production and lab are air gapped so taking a VeeamZIP from production to restore in the lab has always been my go-to option as I've done so many times in the past. Usually I'm able to take a VeeamZIP during the day, however, the MySQL cluster is quite sensitive to disruptions so I can only do backups during our maintenance window (4:05 to 5:00 AM).

I'm not asking for a recurring scheduled task, just a one time schedule of the VeeamZIP. Even a timed delay would be good enough.

Thanks.
MaxKozlov
Influencer
Posts: 19
Liked: 5 times
Joined: Oct 26, 2017 12:52 pm
Full Name: Max Kozlov
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by MaxKozlov »

task scheduler ?
or just

Code: Select all

start-sleep ... ; start-vbrzip... 
?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

As mentioned, you have two options:

- Add sleep interval to the beginning of the script
- Execute script via Task Scheduler at whatever time that suites you

Thanks.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

For everyone struggling with retention policy not being applied to backups stored on a file share, we've just confirmed this to be a bug.

Backup service account is used to apply retention regardless of the specified share credentials. The bug affects both PowerShell and UI.

The bug is planned to be fixed in the next product update.

Thanks.
dartcz
Novice
Posts: 3
Liked: never
Joined: Aug 16, 2018 1:33 pm
Full Name: dartcz
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by dartcz »

Hallo,
I've been using Vladimir's script for some time without problems. Now I have to change destination (Synology CIFS target) , new device.
Connecting to new share (credentials stored in Windows credential manager), same username/passwd for the remote share, in the script only one change has been made...IP :
$Directory = "\\10.0.0.79\veeamzip\daily"

user used for access share: veeamzipacc exist as a local account with same password (server 2012 R2 and Veeam Backup service running under this account)

job failing with :

Code: Select all

16. 8. 2018 15:36:19 :: Processing linux-vm Error: Access is denied.
Failed to process [isFileExists].

[16.08.2018 15:36:28] <  5356> cli|   No impersonation context found for path [\\10.0.0.79\veeamzip].
[16.08.2018 15:36:28] <  5356>      ERR |Failed to check whether file '\\10.0.0.79\veeamzip\daily\linux-vmD2018-08-16T153549.vbk' exists.
[16.08.2018 15:36:28] <  5356>      ERR |Access is denied.
[16.08.2018 15:36:28] <  5356>      >>  |--tr:Error code: 0x00000005
[16.08.2018 15:36:28] <  5356> cli| Client: processing [isFileExists] command Failed.
[16.08.2018 15:36:28] <  5356> cli| Removing stdin/stdout redirector: '754178536048'.

on Synology I can see access with correct user : 
2018/08/16 15:36:28 User [veeamzipacc] from [VBR-VM(10.0.0.80)] via [CIFS(SMB2)] accessed share ...
Using v 9.5.0.823 free

Could you please point me what am I doing wrong ? Thank you very much
Dima P.
Product Manager
Posts: 14396
Liked: 1568 times
Joined: Feb 04, 2013 2:07 pm
Full Name: Dmitry Popov
Location: Prague
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Dima P. »

Hello dartcz.

According to the error it looks like access issue, so check the account/password you are using on the first place. Next step would be to make sure the said destination is accessible via network (location is not blocked by firewalls etc). Cheers!

P.S. You are not using old Veeam B&R version, so I'd recommend to upgrade to the latest Update 3abuild as well.
osguil1
Lurker
Posts: 1
Liked: never
Joined: Aug 28, 2018 9:41 am
Full Name: Olivier SAINT GUILLAIN
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by osguil1 »

Hello,

I've been succesfully using this wonderful script on 2 HyperV, saving my VM's to a NAS : it works perfectly !

I'm now trying to use it on ESXi and I'm having problems :

My script works perfectly if I save my VM's on a local folder ( e.g. d:\TEST ) but if I try to do the same thing on a NAS ( identical to the first with my HyperV's ) it does not work. The backup seems to beggin but after some seconds the script stops and no file is created on my destination ...

Does anybody have some information about that ?

Thank you,

OSG.


PS : please forgive my poor english, I'm not used to.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

If you're backing up VMs to a shared folder, you have to define -NetworkCredentials parameter (credentials to access the shared folder). By the way, what version of Veeam Backup & Replication you're currently at? Thanks.
dartcz
Novice
Posts: 3
Liked: never
Joined: Aug 16, 2018 1:33 pm
Full Name: dartcz
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by dartcz »

Update to 3a with the -NetworkCredentials parameter solve the problem, thanks.
rozza6
Novice
Posts: 5
Liked: never
Joined: Sep 17, 2018 7:12 pm
Full Name: Paul Rowling
Contact:

[MERGED] Stock VeeamZip Backup Script Failing

Post by rozza6 »

Hi,

I'm trying to get the stock VeeamZip powershell backup script working to back up a single Hyper-V Virtual Machine. After populating script variables, when I run the script I receive the following error:

Find-VBRHvEntity : Cannot validate argument on parameter 'Server'. The argument is null. Provide a valid value for the argument, and then try running the command again. At C:\veeam_backup\VeeamZIP.ps1:76 char:48 + $VM = Find-VBRHvEntity -Name $VMName -Server $Server

If I run the following command using the FQDN of the server this returns the relevant info of the Hyper-V Host:

Get-VBRServer -name FQDN Name Of Server

If I run the same command using the IP address of the Hyper-V host or its hostname the command returns nothing.

If I run the following command using the FQDN of the Hyper-V Host I receive the following error:

PS C:\veeam_backup> Find-VBRHvEntity -Name "VM Name" -Server FQDN Name Of Server
Find-VBRHvEntity : Cannot process argument transformation on parameter 'Server'. Host with name 'FQDN Name Of Server' was not found At line:1 char:54 + Find-VBRHvEntity -Name Maval Exchange Server -Server FQDN Name Of Server

Can anyone advise how I rectify this please?
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Stock VeeamZip Backup Script Failing

Post by Mike Resseler »

Hi Paul,
From the error I would think that the variable Server does not get populated. I an assuming that you added the hyper-v host to the mandatory user defined varialbes (under $Hostname = "")

If so, please run the script again, let it fail and then type: $server in the command window to see what the value is. If it is nothing, then type $hostname to see what the value of that variable is
rozza6
Novice
Posts: 5
Liked: never
Joined: Sep 17, 2018 7:12 pm
Full Name: Paul Rowling
Contact:

Re: Stock VeeamZip Backup Script Failing

Post by rozza6 »

Hi Mike,

Thanks for posting. Yep all variables are populated in the script, if I run the following commands after the script has failed both commands return nothing:

$Server
$Hostname

Many Thanks

Paul
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

This means $Server variable does get assigned properly. Check that corresponding Hyper-V host is added to the backup console and you're referring to it within a script, using the exact name. Thanks.
rozza6
Novice
Posts: 5
Liked: never
Joined: Sep 17, 2018 7:12 pm
Full Name: Paul Rowling
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by rozza6 »

Bingo Vladimir!

Completely forgot that Veeam had been resintalled on this Hyper-V host. Added the host to the backup console and the script/backup is now running fine. Thankyou to everyone that posted :-)
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Good to know my input has been helpful. Should other help be needed, let me know. Thanks!
JVarouxis
Lurker
Posts: 2
Liked: never
Joined: Oct 18, 2018 4:06 am
Full Name: Jim Varouxis
Location: Grrece
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by JVarouxis »

Dearr All,

i am using the below script for Hyper-V but cannot find out as i m not very familiar with ps scripting.
Below you will find the script and the error that receive while running the script.
The Version is the of Veeam is the Free one .
Any help would be appreciated.

Code: Select all

===================================================================================
    Asnp VeeamPSSnapin
    # VM names separated by commas
       
    #$VMNames = "A1","A2","A3"

    # vCenter name/IP
    $HostName = “10.230.0.97”
    
    $NETCRED = Get-VBRCredentials -Name "NAS\ACC"

    # Directory that VM backups should go to
    $Directory = "\\10.230.0.130\veeam\"
    
    # Desired compression level, following compression level from Veeam (Optional)
    $CompressionLevel = “5”

    # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
    $EnableQuiescence = $True

    # Protect resulting backup with encryption key (Optional; $True/$False)
    $EnableEncryption = $False

    # Encryption Key (Optional; path to a secure string, C:\SecureString.txt”
    $EncryptionKey = “”

    # 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 = “Tonight”

    # Email Settings

    # Enable notification (Optional)
    $EnableNotification = $True
    
    # Email SMTP server
    $SMTPServer = “MY MAIL”

    
    # Email FROM
    $EmailFrom = “Veeam@mydomain”

    # Email TO 
    $EmailTo = "Veeam@mydomain"
    
    #EmailTo SUCCESS
    $EmailToSUCCESS = "VeeamS@mydomain"

    #EmailTo Failure
    $EmailToFAILED = "VeeamF@mydomain"

    # Email subject
    $EmailSubject = “Veeam Backup Job"
    # Email formatting

    $EmailSubjectSUCCESS = "SUCCESS - Veeam Backup Job "

    $EmailSubjectFAILED = "FAILED - Veeam Backup "


  # SUCCESS
$styleSUCCESS = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$styleSUCCESS = $styleSUCCESS + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$styleSUCCESS = $styleSUCCESS + "TH{border: 1px solid black; background: #4CAF50; color: white; padding: 5px;}"
$styleSUCCESS = $styleSUCCESS + "TD{border: 1px solid black; padding: 5px;}"
$styleSUCCESS = $styleSUCCESS + "</style>"

# FAILED
$styleFAILED = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$styleFAILED = $styleFAILED + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$styleFAILED = $styleFAILED + "TH{border: 1px solid black; background: #FB5A5A; color: white; padding: 5px;}"
$styleFAILED = $styleFAILED + "TD{border: 1px solid black; padding: 5px;}"
$styleFAILED = $styleFAILED + "</style>"


    ##################################################################
    # End User Defined Variables
    ##################################################################

    #################### DO NOT MODIFY PAST THIS LINE ################
    Asnp VeeamPSSnapin

    $Server = Get-VBRServer -name $HostName
    $mbody = @()

    foreach ($VMName in $VMNames)
    {
    $VM = Find-VBRhVEntity -Name $VMName -Server $Server 
    $fullpath = join-path -path $Directory -childpath $VMName 
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $fullpath -NetworkCredentials $NETCRED -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
    
    If ($EnableNotification) 
    {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"} 
    if ($FailedSessions -ne $Null)
    {
    $EmailTo = $EmailToSUCCESS , $EmailToFAILED
    $EmailSubject = $EmailSubjectFAILED
    $MesssagyBody += $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
    $style = $styleFAILED
    } 
    Else
    {
    $EmailTo = $EmailToSUCCESS
    $EmailSubject = $EmailSubjectSUCCESS
    $MesssagyBody += $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
    $style = $styleSUCCESS
    }
    }
   }
  
    If ($EnableNotification)
    {
    foreach ($EmailTo in $EmailTo)
    {
   $Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
   $Message.Subject = $EmailSubject 
   $Message.IsBodyHTML = $True
   $message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
   $SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
   $SMTP.Send($Message)
    }
   }

======================================================
======Error received 


PS C:\Backup> C:\Backup\Test.ps1
Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Backup\Test.ps1:91 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $fullpath -Network ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
 
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Backup\Test.ps1:108 char:5
+     $MesssagyBody += $MesssagyBody + ($ZIPSession | Select-Object @{n ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

======================================================
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Mike Resseler »

Hi Jim,

First: Welcome to the forums
Second: I think your $VM variable is empty, which most probably means it didn't got the response needed from one of the previous commands in the PowerShell script. My suggestion to troubleshoot:
Load the entire script in Windows PowerShell ISE and run it line by line. 2 lines before the $ZIPSession = Start-VBRZip... you will see a command which is: $VM = Find-VBRhVEntity -Name $VMName -Server $Server. After that line, you need to type in the command window $VM and enter. That should give you some result and not blanc as I assume it is now.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Check whether the Hyper-V host is added to backup console and whether you're referencing it within the script, using the exact name (as the one that is shown in backup server). Thanks.
JVarouxis
Lurker
Posts: 2
Liked: never
Joined: Oct 18, 2018 4:06 am
Full Name: Jim Varouxis
Location: Grrece
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by JVarouxis »

Dear Mike & Eremin,
Thannk you both for your replies .

i have corrected the code and the SVMNames have the Vn as in the Hostname,
But i receive the same error as below :
=============================================================================================================
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At C:\Backup\neo2.ps1:98 char:5
+ $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
==========================================================================================================
Mike Resseler
Product Manager
Posts: 8044
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Mike Resseler »

Did you receive also again that first part of the error or is that gone?

The:
tart-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Backup\Test.ps1:91 char:40
+ $ZIPSession = Start-VBRZip -Entity $VM -Folder $fullpath -Network ...
+ ~~~
+ CategoryInfo : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Something must be wrong with the way you try to create an email report. Error says that the corresponding object $MessageBody of PSObject type doesn't support addition method (the one represented by + sign). Thanks!
okanog
Lurker
Posts: 1
Liked: never
Joined: Nov 20, 2018 3:00 pm
Full Name: okan koc
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by okanog »

Hi @v.Eremin

What do you mean with "Name of my VC" in the script?
I would now use your script but it is not working.

regards
okanog
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Name of your vCenter server or ESXi host VMs to backup reside on. You should use the exact name under which this server is added to your backup server. Thanks!
Grigilo
Lurker
Posts: 1
Liked: never
Joined: Nov 22, 2018 1:52 pm
Full Name: Gregory Tsoy
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Grigilo »

Hi all
i have Veeam BR free edition, hyper-v,vm
I want to configure the script in the scheduler
everything starts from the console VBR
but my script gives an error
maybe someone knows what the problem might be. thx

Code: Select all

Start-VBRZip : Cannot check the argument for the "Entity" parameter. The argument is NULL. Specify a valid value for the argument, and then repeat the command.
C:\Users\tst\Documents\tt.ps1:86 char:41
+     $ZIPSession = Start-VBRZip  -Entity $VM -Folder $Directory -Compression $Com ...
+                                         ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Kindly, check the answers provided previously. Thanks!
BlueToast
Lurker
Posts: 2
Liked: never
Joined: Nov 26, 2018 3:39 am
Full Name: Joshua Szántó

Re: Start-VBRZip in Veeam Backup Free Edition

Post by BlueToast »

Hello! I am using VEEAM Free Edition with a PowerShell script on a Hyper-V host to backup its virtual machines. You can find the very .PS1 script I am using below.

The problem I have encountered is that today I added a second Hard Drive to a virtual machine CONTOSO-DC1 to store non-OS company data, and moved some important data off of the first Hard Drive (represents volume C: for OS) on to the second Hard Drive (representing volume D: for Data). When the VEEAM PowerShell script on CONTOSO-HV1 ran on schedule and finished, I examined the backups folder where VBK files are stored and found that CONTOSO-DC1's VBK file is significantly smaller in file size than expected when compared to past VBK files for this virtual machine. It looks as though VEEAM skipped over the second Hard Drive in virtual machine CONTOSO-DC1 and did not back it up. How can I fix this?

Code: Select all

##################################################################
#                   User Defined Variables
##################################################################
# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = Get-VM
#$VMNames = Get-VM | Where-Object {$_.Name -Like "*CONTOSO*"}

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "CONTOSO-HV1"

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "D:\VEEAM"

# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme) 
$CompressionLevel = "9"

# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $False

# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False

# Encryption Key (Optional; path to a secure string)
$EncryptionKey = ""

# 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 = "In1Week"

##################################################################
#                   Notification Settings
##################################################################

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = "smtp.gmail.com"

# Email SMTP Server Port
$SMTPServerPort = "587"

# Email FROM
$EmailFrom = "noreply@contoso.com" 

# Email TO
$EmailTo = "noreply@contoso.com"

# Email subject
$EmailSubject = "VEEAM Backup Report"

##################################################################
#                   Email formatting 
##################################################################

$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"

##################################################################
#                   End User Defined Variables
##################################################################

#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin

$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRHvEntity -Name $VMName.Name -Server $Server
  
  If ($EnableEncryption)
  {
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
  }
  
  Else 
  {
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
  }
  
  If ($EnableNotification) 
  {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
  
  if ($FailedSessions -ne $Null)
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
  }
   
  Else
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
  }
  
  }   
}
If ($EnableNotification)
{
# Commented lines are test lines
#$MessageBody = "Test"
#$SMTPServer = "smtp.gmail.com"
#$SMTPServerPort = "587"
#$EmailFrom =  "noreply@contoso.com"
$EmailPassword = "passwordhere"
#$EmailTo = "noreply@contoso.com"
#$EmailSubject = "VEEAM Backup Report"
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$Message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer, $SMTPServerPort)
$SMTP.EnableSsl = $True
$SMTP.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, $EmailPassword);
$SMTP.Send($Message)
#Send-MailMessage -From $EmailFrom -to $EmailTo -Subject $EmailSubject -Body $Message -SmtpServer $SMTPServer -Port 587 -UseSsl -Credential (Get-Credential)
}

# Found on Spiceworks: https://community.spiceworks.com/scripts/show/3951-veeam-free-scheduled-backup-powershell?utm_source=copy_paste&utm_campaign=growth
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

What is the type of newly added virtual disk? Is it ordinary virtual disk it physical RDM by any chance? Thanks!
BlueToast
Lurker
Posts: 2
Liked: never
Joined: Nov 26, 2018 3:39 am
Full Name: Joshua Szántó

Re: Start-VBRZip in Veeam Backup Free Edition

Post by BlueToast »

Hello v.Eremin, thank you for your reply! The newly added virtual disk is an ordinary Hyper-V VHDX virtual disk. Virtual machine CONTOSO-DC1 previously only had one VHDX, now it has two; and, both VHDX virtual disks are found in Hyper-V's configured VHD location (in this case "C:\Data\Hyper-V\VHD" on Hyper-V host CONTOSO-HV1).
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

OK, you can double VeeamZIP session in backup server console and see whether any disks have been skipped from processing.

If you don't find any warnings there, it will mean that everything has been backed up successfully. To be on the safe side you can perform test restore.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests