PowerShell script exchange
Post Reply
navs
Novice
Posts: 7
Liked: never
Joined: Jun 22, 2016 8:16 am
Full Name: Nav Sangha
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by navs »

Hi,

The VBR product is installed on the Hyper-v server, and yes i can see it it listed under infrastrcture>microsoft hyper-v>zf-hyperhost01. I just changed the $hostname variable to lowercase and it seems to be backing up now. So lets see how that gets on and then i can test the email part. Fingers crossed it all works.

Quick question, the $directory variable, can i add that in as a unc path,i.e. \\backupserver\backuplocation?
veremin
Product Manager
Posts: 20404
Liked: 2298 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 previous answers provided above. The usage of share as a backup target has been several times already. Thanks.
navs
Novice
Posts: 7
Liked: never
Joined: Jun 22, 2016 8:16 am
Full Name: Nav Sangha
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by navs »

Hi, i have been looking at network share access on and off last week, and have it working but not exactly how i want it.

1. I can write to a share on a windows server, as long as i add in the computer account to the RW NTFS and share permissions.
2. I would like to backup my VMs to a qnap NAS, however it doesnt have the option to add computer accounts to its permissions, i am also not great in powershell so i was wondering if there was a way i can prepend the start-vbrzip script with some entries to add a share and specify permissions to use for the backup job.
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

We're currently thinking about the way the said commandlet can be enhanced to address this very goal. Chances are, potential enhancements will see the light in one of the next product versions. Thanks.
abitson
Lurker
Posts: 1
Liked: never
Joined: Feb 11, 2016 5:49 pm
Full Name: Andrew Bitson
Contact:

[MERGED] Using PowerShell and VeeamZip to automate backups

Post by abitson »

I'd like to use Windows Scheduler and a PowerShell script to initiate an automatic VeeamZip of our hosts to an external SMB sharepoint.

The external SMB sharepoint is not joined to the domain and requires authentication, so UNC pathing will not work.

I can mount the SMB share using New-PSDrive with -Persist and the SMB share mounts just fine for browsing in Explorer, but then when starting the backup with Start-VBRZip, it fails -- must be run as an administrator. If we try the script when running Powershell as administrator, we get a failure

Code: Select all

Processing VMName: The system cannot find the path specified. Failed to create or open file [V:\VMName.vbk]
The command I'm using is here (I'm building the credentials just above this line)

Code: Select all

New-PSDrive -Name "V" -PSProvider FileSystem -Root \\192.168.100.123\SMB -Credential $miniCredentials -Persist -Scope Global
Start-VBRZip -Entity $vm -Folder "V:\" -Compression 5 -DisableQuiesce -AutoDelete Never -RunAsync
I'm not a Powershell expert and I'm learning this as I go, but I've learned that mount a drive in a Powershell session is unique to that session unless -Persist is used. If you are also executing the Powershell in admin space, then it's still a temporary mount only available to the PS session and not the user who kicked on the script, despite the -Persist flag.

Somehow I need to be able to start a VeeamZip to our external SMB share and have it run weekly. I can do this by hand for now, but that's never a good long term strategy.
Nosferatu
Lurker
Posts: 2
Liked: never
Joined: Jul 18, 2016 2:13 pm
Full Name: Peter Kirk

[MERGED] $Retention dosent work, disk keeps filing up

Post by Nosferatu »

Hey Everybody.

I run a backup via scheaduled tasks, this task runs a powershell scripts as the guide here shows.
Works great, except the part that should delete old files :(

Any suggestions why this happens ? Or where in the log files i created in Veeam should I look ?


Im on Server 2008 R2 Enterprise
Powershell 4.0
Veeam backup and replication 9.0 version 9.0.0.1491
Saving to a Qnap ISCSI Storage

https://www.veeam.com/blog/veeam-backup ... shell.html

Code: Select all

# 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"
I have tried updating Veeam to latest edition, but still the same problem
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Just checked the script as well as retention portion and everything appears to be fine.

Can you tell me how did you come to the conclusion that retention settings were not applied? Backup files stayed in the given directory longer than they were supposed to? Could you try to specify different values and see whether they work or not? (say, Tonight or TomorrowNight)? Thanks.
Nosferatu
Lurker
Posts: 2
Liked: never
Joined: Jul 18, 2016 2:13 pm
Full Name: Peter Kirk

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Nosferatu »

v.Eremin wrote:Just checked the script as well as retention portion and everything appears to be fine.

Can you tell me how did you come to the conclusion that retention settings were not applied? Backup files stayed in the given directory longer than they were supposed to? Could you try to specify different values and see whether they work or not? (say, Tonight or TomorrowNight)? Thanks.
Yes they stay there forever.

I tried to change from in2week to in1week. Did not solve the problem.

Ended up addind this to my powershell scripts.

Code: Select all

$limit = (Get-Date).AddDays(-15)
$path = "x:\folder\server"

# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force

EDIT

Maybe it is because Veeam backup and replication keeps saying I need to switch to free mode ?

Imageonline photo sharing
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Maybe it is because Veeam backup and replication keeps saying I need to switch to free mode ?
I don't think it's related anyhow.

What I'd suggest is to try shorter retention that can be verified within a day (Tonight or TomorrowNight) and execute the same operations via GUI to limit the scope of potential suspects.

Thanks,
enoch85
Novice
Posts: 5
Liked: never
Joined: Jul 19, 2016 8:09 pm
Full Name: Daniel Hansson
Contact:

[MERGED] VeeamZIP fails to backup to NAS with Powershell

Post by enoch85 »

Using this script: https://www.veeam.com/blog/veeam-backup ... shell.html

I have an issue regarding sending the Veeam backup files to a NAS in the same subnet in Powershell. I have mounted the NAS in Windows (on the PC that has Veeam installed, 192.168.1.110) as a Network Drive, and I can login and view the files if I use the standard File Explorer, but with Powershell I can't write to that NAS directory. The DIR I use for storing backups is "veeam" on the NAS, like this:

Code: Select all

$Directory = "\\192.168.1.115\veeam"
It works if I do it from the GUI, but with Powershell also works (the script is executed correctly and tries to backup as it normally would do) to the point where it writes to the $Directory and there it fails. I think it's becuase it needs permission (the share is password protected and I can't change that) in form of login credentials. I get an error something like this in Veeam:

Code: Select all

"[BACKUP] Failed to create directory '\\192.168.1.115\veeam' The system cannot find the path specified. CreateDirectory(\\192.168.1.115\veeam) function call failed. Cannot create folder. Folder path: [\\192.168.1.115\veeam]. --tr:FC: Failed to create directory. Directory path: [\\192.168.1.115\veeam]. --tr:Failed to call DoRpc. CmdName: [FcCreateDir] inParam: [<inputarguments><dirname value="\\192.168.1.115\veeam"/></inputarguments>]."
I also tried to give "Guest" full access on the NAS, but no luck there either. In Linux it would be easy, just create a password file or something and then use that credentials, but in Powershell I don't have a clue. I tried a few things already though, keep reading.

When I do "Get-PSDrive" in Powershell, the Network Drive shows up as "Q" which is Q:\ on my Windows system that is assigned to the Network Drive in Windows.

I have also tried to remove Q:\ as a Network Drive and remount it within Powershell (don't know if that would make a difference, but I was thinking that Powershell maybe caches the password in a different way than if I do it in Windows GUI?) with this command:

Code: Select all

New-PSDrive -Name Q -PSprovider Filesystem -Root \\192.168.1.115\veeam -Credential VEEAM_NAS -Persist
But it fails as it says "Multiple connections to a server or shared resource by the same user, using more than one user name are not allowed. Disconnect all previous connections to the server or shared resource and try again" and can't create a new PSDrive. Because of this I tried to remove all the Shared Storages with "net use * /delete" but it says that "The list is empty" aka no Shared Storages. So it shouldn't be a problem to create a new drive, but it is.

I have also tried to change IP on the NAS so that Windows would think it's a new Storage, but that didn't work either. I also checked all the shared resources in services.msc but nothing was shared there either. I have also tried to flush DNS and renew DHCP, but no luck. So in other words, it says that I have shared resources but I don't.

And yes, I rebooted both the NAS and the Windows machines several times. I'm stuck! As I see it there are a couple of options that I haven't tried yet:

1. Re-format the Windows PC (192.168.1.110) to clean up everything and start over
2. Maybe Veeam uses the same credentials as in Windows(?), and therefore change the NAS user to the same user as in Windows, also with the same password ofc.
3. http://www.serverlab.ca/tutori...

The NAS is a QNAP 269 Pro Turbo, and the Windows Machine is Windows 10 Pro clean install.

Should I enter some additional $Variable to the script to get this working, or do you have some other suggestion? Please help!
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

There have been several troubleshooting steps mentioned in this thread. So, kindly, take a look. Thanks.
enoch85
Novice
Posts: 5
Liked: never
Joined: Jul 19, 2016 8:09 pm
Full Name: Daniel Hansson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by enoch85 »

v.Eremin wrote:There have been several troubleshooting steps mentioned in this thread. So, kindly, take a look. Thanks.
As you can see in my post I have tried most of them. But after reading the whole thread there is one thing that I will try that might work - Giving the VBR account full access to the Network Share/Drive. I'll let you know if it works. Thanks for being so helpful to all of us!
enoch85
Novice
Posts: 5
Liked: never
Joined: Jul 19, 2016 8:09 pm
Full Name: Daniel Hansson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by enoch85 »

v.Eremin wrote:There have been several troubleshooting steps mentioned in this thread. So, kindly, take a look. Thanks.
Now another day has passed and I tried it all, even making the QNAP a domain controller and connecting to it, which also failed. I called support, but they doesn't support powershell and told me to come back to the forums.

How exactly do I add the local user account to the share as mentioned in the forums?

What I've tried:
1. Add a network share in Windows 10 (can connect via Windows)
2. New-PSDrive in Powershell (network drive shows up with Get-PSDrive, but the script fails)
3. Doing the backup job from GUI (works)
4. Add the QNAP as a Linux Server (can add it and connect, but can't get DIR listing)
5. Making the QNAP a domain controller and connect my Veeam laptop to it (Windows 10, fails)
6. Add the QNAP as SMB storage with SMB 3 (fails to find the QNAP)
7. Change Workgroup so that the QNAP and the Veeam PC share the same seperate Workgroup
8. Adding varoius paths in the script \\Qnap-backup\veeam, \\192.168.1.115\veeam, VeeamQ\veeam (name of the network share)
9. Added NFS share on the QNAP and tried to connect (failed)
10. + More that I forgot by now.


Please help.
enoch85
Novice
Posts: 5
Liked: never
Joined: Jul 19, 2016 8:09 pm
Full Name: Daniel Hansson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by enoch85 »

OK so I've tried some variations of the script, but none of them seems to work.

https://github.com/enoch85/scripts/blob ... s1#L55-L73

I'm still stuck at the fact that Windows recognizes and allows me to write to the share, but Windows don't. Btw, I try to do this on a local computer in my network, to a local NAS in the same subnet. And I can still execute the job in GUI with success.
furian
Lurker
Posts: 1
Liked: never
Joined: Aug 12, 2016 7:25 am
Full Name: furian
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by furian »

Hi all,

We've been using the free version for a while now, and it works fine.
Using the powershell script (https://www.veeam.com/blog/veeam-backup ... shell.html to do the backup and using the file copy job from within veeam to back it up to usb.

However everytime the backup is created its a full backup.

Is there a way to use an incremental backup setting from within the script?
Vitaliy S.
VP, Product Management
Posts: 27375
Liked: 2799 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Vitaliy S. »

Free edition allows creating full backups only, if you need more options (such as incremental, AAIP etc.), then full version of Veeam B&R should be used. Thanks!
Firemaster
Lurker
Posts: 2
Liked: 1 time
Joined: Aug 16, 2016 7:51 am
Full Name: Craig Parkinson
Contact:

[MERGED] Backup to NAS

Post by Firemaster »

Using Backup and replication free, and the powershell module. i am able to run backups for our VM's. However, this is only if i use a local hardware drive on the server.

We would like to backup to either a mapped drive or a UNC path. \\nasname\VMbackups. this runs, finds the VM and the size but fails to backup. no errors.
I can run copyitem from powershell to the remote location so permissions is not an issue.

Code: Select all

$VMNames = "servername"
## This works fine ##
$HostName = “192.168.50.50"
$Directory = “E:\backups" #(Local hardDisk)#
$CompressionLevel = “5”
$EnableQuiescence = $False
$EnableEncryption = $False
$EncryptionKey = “”
$Retention = “In2Weeks” 

## this Fails to backup ##

$VMNames = "servername"
$HostName = “192.168.50.50"
$Directory = “\\naslocation\backups\" # or F:\vmbackups as a mapped drive to that location#
$CompressionLevel = “5”
$EnableQuiescence = $False
$EnableEncryption = $False
$EncryptionKey = “”
$Retention = “In2Weeks”

Both the above have the rest of this script but you dont have to change any of this if you dont need to.

$EnableNotification = $false

$SMTPServer = “smtp.smtp.co.uk”

$EmailFrom = “Person@company.co.uk”

$EmailTo = “Admin.Person@Comapny.co.uk”

$EmailSubject = “Veeam Backup Job”

$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: #54b948; 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
$mbody = @()
foreach ($VMName in $VMNames)
{
$VM = Find-VBRViEntity -Name $VMName -Server $Server
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
If ($EnableNotification)
{
$TaskSessions = $ZIPSession.GetTaskSessions()
$FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}
if ($FailedSessions -ne $Null)
{
$mbody = $mbody + ($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
{
$mbody = $mbody + ($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)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $mbody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

A lot of people in this thread said that granting Veeam account as well as Computer account read/write permissions on the given share have helped them to solve the said issue. Thanks.
Firemaster
Lurker
Posts: 2
Liked: 1 time
Joined: Aug 16, 2016 7:51 am
Full Name: Craig Parkinson
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Firemaster » 1 person likes this post

Adding the actual computer account to the share worked, not just the user account. Happy days 8)
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Granting permissions to the rescue. :D Thank you for finding time and updating the topic with the results of your findings; appreciated.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

[MERGED] Return values of Start-VBRZip

Post by Darkyputz »

Hello!

I used a modified version of the available free veeam backup script...
Was working fine and i got mails with statistics...
But something changed...
Every backup starts with :

Code: Select all

$bk_result = Start-VBRZip...
So the variable gets filled with the return values of the process...
And some deeper in my script, an email gets formatted with colors etc:

Code: Select all

foreach($result in $aBkResult)
{
$result_color = ""
if ($result.result -eq "Success")
{
$result_color = "green"
But...these Values Success etc are not found by the script anymore...
They worked, and now it passes the whole if segment with out doing anything...
I checked via debug what comes abck, and there is not even a variable for 'result'...
Can someone help?!

Thx in advance
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Did it the script generate any error or something? Can you also provide a whole script, so that we can see what is wrong with it? Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Hello...no error...just not the full experience...which i was counting on...smile...
Here is the script...
It backs up...and sends a message when not successful with colorful report...worked like a charm...but somehow the returnvalue "result" seems to be gone all the sudden

Code: Select all

#set-executionpolicy unrestricted


[CmdletBinding()]
param(
#vSphere host parameters
$vsphere_host = '192.168.xxx.xxx',
$vsphere_user = 'xxxxxxx',
$vsphere_password = 'xxxxxxx',

#Backup parameters see http://helpcenter.veeam.com/backup/80/powershell/start-vbrzip.html
$bk_repository = "\\HCTLOAN\VeeamBackup\",
#$bk_repository = "c:\backup\",
    #$bk_repository = Get-VBRBackupRepository -name "Veeamserver",
#$bk_quiesce = "",
#$bk_quiesce = "-DisableQuiesce"
#Possible vlaues: Never, Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month
$bk_autodelete = 'In1Week',
#Possible values: 0,4,5,6,9 at higher values corresponds more compression and more cpu usage
$bk_compression = 9,

#Email report parameters
$mail_send = "true",
$mail_smtp = 'xxxxxxxx',
$mail_sender = 'xxxxxxx',
$mail_recipient = 'xxxxxxxxx',

#Virtual machines names to exclude for the backup process
       $includedVM = ("Machine1", "Machine2")
   #$includedVM = (" ")
    
)

if ( (Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin "VMware.VimAutomation.Core"
}

if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PSSnapin VeeamPSSnapIn
}


Connect-VIServer -Server $vsphere_host -User $vsphere_user -Password $vsphere_password

$hosts = Get-VMHost
$hosts = $hosts | Sort-Object -property name

foreach($vmHost in $hosts)
{
write-host "Backing up host: " $vmHost.name
$result = Get-VMhost $vmHost.name | Get-VM | Where-Object {$_.VMHost.Name -eq $vmHost.name}
$aBkResult = @()
    $resultbackup = "Success"
foreach($vm in $result)
{
if ($includedVM  -contains $vm.name)
{
Write-Host "Backing up vm: $vm"
$vm_tobackup = Find-VBRViEntity -Name $vm
                        $path_tobackup = $bk_repository + $vm
                        Write-Host "Path to backup: $path_tobackup"
#BACKUP VM
            if(!(Test-Path -Path $path_tobackup ))
            {
                New-Item -ItemType directory -Path $path_tobackup
            }
$bk_result = Start-VBRZip -Folder $path_tobackup -Entity $vm_tobackup -Compression $bk_compression -autodelete $bk_autodelete
$aBkResult = $aBkResult + $bk_result
}
}
}


###Create the mail report
$mail_text = $mail_text + "<tr align='center'><b><td>JOB NAME</td><td>START TIME</td><td>END TIME</td><td>DURATION (min.)</td><td>RESULT</td></b></tr>"
foreach($result in $aBkResult)
{
$result_color = ""
if ($result.result -eq "Success")
{
$result_color = "green"
}
elseif ($result.result -eq "Warning")
{
$result_color = "yellow"
}
elseif ($result.result -eq "Failed")
{
$result_color = "red"
}
$duration = new-timespan –Start $result.CreationTime –End $result.endtime

$mail_text = $mail_text + "<tr><td>" +$result.JobName+ "</td><td>" +$result.CreationTime+ "</td><td>" +$result.endtime+ "</td><td>" +$duration.TotalMinutes+ "</td><td bgcolor='$result_color'>" +$result.result + "</td></tr>"
}

$mail_body = "<html>
<b>VeeamFree complete backup script report:<br /><br /></b>
<table border='1'>
$mail_text
</table>
<html>"
#####

#Send email report if enabled
if ($mail_send)
{
#Write html report
$mail_body = $mail_body + $mail_result
$mail_body | Out-File $bk_repository\VeeamFreeCBSReport.html
###
    if ($result.result -ne "Success")
{
   $mail_result = send-mailmessage -from $mail_sender -to $mail_recipient -subject "VeeamFree backup report" -bodyashtml $mail_body -smtpServer $mail_smtp
    }
}
###


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

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Can you try to double check whether any of those variables contains data? $bk_result, $aBkResult, $result? Thanks,
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

bk_result contains the whole load of info of the job...
aBkResult is like an array filled with the whole series of jobs done
And result is empty...because it looks like the result return value went away from the bk_result content...
veremin
Product Manager
Posts: 20404
Liked: 2298 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 $Bk_result variable has a backup session assigned (as it's supposed to), then, there should be a Result property available.

You can easily check it by getting one session and seeing whether it contains corresponding property.

Image

Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Result shows up for me as well...strange...
But why did it stop finding it in the if statements to do some work with it?!
Can you see if the script shows anything weird?
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

My guess would be that the said property is still there, though it doesn't contain any data - null object in other words. I will try to accommodate the script for my environment and run it later on. Thanks.
Darkyputz
Enthusiast
Posts: 27
Liked: never
Joined: Feb 16, 2016 7:51 pm
Full Name: Jan Meinecke
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by Darkyputz »

Any luck with your test in your environment?!
veremin
Product Manager
Posts: 20404
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Yep. My report contains reflects result property as expected:

Image

Aren't you using PowerShell 2.0 by any chance?

Thanks.

Below is the modified version of your script that I'm using:

Code: Select all

    #set-executionpolicy unrestricted


    [CmdletBinding()]
    param(
    #vSphere host parameters
    #$vsphere_host = '192.168.xxx.xxx',
    #$vsphere_user = 'xxxxxxx',
    #$vsphere_password = 'xxxxxxx',

    #Backup parameters see http://helpcenter.veeam.com/backup/80/powershell/start-vbrzip.html
    $bk_repository = "D:\VeeamZIP",
    #$bk_repository = "c:\backup\",
        #$bk_repository = Get-VBRBackupRepository -name "Veeamserver",
    #$bk_quiesce = "",
    #$bk_quiesce = "-DisableQuiesce"
    #Possible vlaues: Never, Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month
    $bk_autodelete = 'In1Week',
    #Possible values: 0,4,5,6,9 at higher values corresponds more compression and more cpu usage
    $bk_compression = 9,

    #Email report parameters
    $mail_send = "true"
    #$mail_smtp = 'xxxxxxxx',
    #$mail_sender = 'xxxxxxx',
    #$mail_recipient = 'xxxxxxxxx',

    #Virtual machines names to exclude for the backup process
    #$includedVM = ("Machine1", "Machine2")
       #$includedVM = (" ")
       
    )

    #if ( (Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null )
    #{
    #    Add-PSSnapin "VMware.VimAutomation.Core"
    #}

    if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null )
    {
        Add-PSSnapin VeeamPSSnapIn
    }


    #Connect-VIServer -Server $vsphere_host -User $vsphere_user -Password $vsphere_password
    #
    #$hosts = Get-VMHost
    #$hosts = $hosts | Sort-Object -property name

    #foreach($vmHost in $hosts)
    #{
    #write-host "Backing up host: " $vmHost.name
    #$result = Get-VMhost $vmHost.name | Get-VM | Where-Object {$_.VMHost.Name -eq $vmHost.name}
    $result = “Name of first VM”,”Name of second VM”
    $aBkResult = @()
    $resultbackup = "Success"
    foreach($vm in $result)
    {
    #if ($includedVM  -contains $vm.name)
    #{
    Write-Host "Backing up vm: $vm"
    $vm_tobackup = Find-VBRViEntity -Name $vm -server (Get-VBRServer -name "Name of my VC")
                            $path_tobackup = $bk_repository + $vm
                            Write-Host "Path to backup: $path_tobackup"
    #BACKUP VM
                if(!(Test-Path -Path $path_tobackup ))
                {
                    New-Item -ItemType directory -Path $path_tobackup
                }
    $bk_result = Start-VBRZip -Folder $path_tobackup -Entity $vm_tobackup -Compression $bk_compression -autodelete $bk_autodelete
    $aBkResult = $aBkResult + $bk_result
    }
    #}
    #}


    ###Create the mail report
    $mail_text = $mail_text + "<tr align='center'><b><td>JOB NAME</td><td>START TIME</td><td>END TIME</td><td>DURATION (min.)</td><td>RESULT</td></b></tr>"
    foreach($result in $aBkResult)
    {
    $result_color = ""
    if ($result.result -eq "Success")
    {
    $result_color = "green"
    }
    elseif ($result.result -eq "Warning")
    {
    $result_color = "yellow"
    }
    elseif ($result.result -eq "Failed")
    {
    $result_color = "red"
    }
    $duration = new-timespan –Start $result.CreationTime –End $result.endtime

    $mail_text = $mail_text + "<tr><td>" +$result.JobName+ "</td><td>" +$result.CreationTime+ "</td><td>" +$result.endtime+ "</td><td>" +$duration.TotalMinutes+ "</td><td bgcolor='$result_color'>" +$result.result + "</td></tr>"
    }

    $mail_body = "<html>
    <b>VeeamFree complete backup script report:<br /><br /></b>
    <table border='1'>
    $mail_text
    </table>
    <html>"
    #####

    #Send email report if enabled
    if ($mail_send)
    {
    #Write html report
    $mail_body = $mail_body + $mail_result
    $mail_body | Out-File $bk_repository\VeeamFreeCBSReport.html
    ###
    #    if ($result.result -ne "Success")
    #{
    #   $mail_result = send-mailmessage -from $mail_sender -to $mail_recipient -subject "VeeamFree backup report" -bodyashtml $mail_body -smtpServer $mail_smtp
    #    }
    }  
    ###
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests