PowerShell script exchange
Post Reply
vraengmose
Influencer
Posts: 16
Liked: 2 times
Joined: Jun 18, 2019 9:46 am
Full Name: Thomas Trolle Vrøngmose
Contact:

SureBackup job with random VM through PowerShell

Post by vraengmose »

Hi

I am looking for a good way to test our backups on a monthly schedule task, with random VM selection dievideng them op ind to different application groups like:

Domain Controller SureBackupTest
File leve SureBackupTest
Disaster Recovery SureBackupTest
SQL SureBackupTest

With different setting on the application group. Anybody who tried something similar to this?

i looked ad post: veeam-backup-replication-f2/surebackup- ... 30402.html

Code: Select all

$NumberofVMs = 10
$AppGroupName = "Dynamic App Group"
$SbJobName = "Dynamic Surebackup Job"
$SbJobDesc = "Dynamic App Testing"
 
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
 
# Find all VM objest successfully backed up in last 1 days
$VbrObjs = (Get-VBRBackupSession | ?{$_.JobType -eq "Backup" -and $_.EndTime -ge $Date.adddays(-1)}).GetTaskSessions() | ?{$_.Status -eq "Success" -or $_.Status -eq "Warning" }
 
# Select random VMs to be tested
$TestVMs = $VbrObjs | Get-Random -Count $NumberofVMs
 
# Remove the old App Group
Remove-VSBJob -Job (Get-VSBJob -Name $SbJobName) -Confirm:$false
Remove-VSBApplicationGroup -AppGroup (Get-VSBApplicationGroup -Name $AppGroupName) -Confirm:$false
 
# Create the new App Group, SureBackup Job, Start the Job
$VirtualLab = Get-VSBVirtualLab -Name "Surebackup Lab”
$AppGroup = Add-VSBViApplicationGroup -Name $AppGroupName -VmFromBackup (Find-VBRViEntity -Name $TestVMs.Name)
$VsbJob = Add-VSBJob -Name $SbJobName -VirtualLab $VirtualLab -AppGroup $AppGroup -Description $SbJobDesc

Start-VSBJob -Job $VsbJob -RunAsync

But the can't get it to work. Maybe i need more powershell skilles :wink:
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: SureBackup job with random VM through PowerShell

Post by jhoughes » 1 person likes this post

Start with reading this blog from Luca, it should help.

https://www.virtualtothecore.com/can-te ... urebackup/
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
vraengmose
Influencer
Posts: 16
Liked: 2 times
Joined: Jun 18, 2019 9:46 am
Full Name: Thomas Trolle Vrøngmose
Contact:

Re: SureBackup job with random VM through PowerShell

Post by vraengmose »

Thanks Joe!

I am already started testing script and looking ind to modifying it for our needs.
sandsturm
Veteran
Posts: 279
Liked: 23 times
Joined: Mar 23, 2015 8:30 am
Contact:

[MERGED] Sure Backup automation and report

Post by sandsturm »

Hi
My idea is to have a script, that executes VM recovery tests with SureBackup on an amount of virtual machines. I want to run the script every night, let's say to test 50-80 VM recovery tests of a total amount of 1300 VMs and do this again the next night until all VMs are tested. To be able to do that dynamically (with different VMs in the next run) via script, the script removes the Surebackupjob and ApplicationGroup after it ran and therefore I have no chance to create a VeeamONE report of SureBackup jobs, because the SureBackup job is not there any more after it was executed once.
I need a report for audit reasons, is it possible to create a report via powershell within my script, that generates a report or something like the one which is visible as html report in Veeam or something? I haven't found anything til now.

thx
sandsturm
Egor Yakovlev
Veeam Software
Posts: 2537
Liked: 683 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: SureBackup job with random VM through PowerShell

Post by Egor Yakovlev »

Hi Sandstrum,
I have moved your post to the respectful part of Veeam Forums. Please check answers above and that script from Luca, that does exactly what you need.
/Cheers!
sandsturm
Veteran
Posts: 279
Liked: 23 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: SureBackup job with random VM through PowerShell

Post by sandsturm »

Hi Egor

That's exactly the script I use as the basis for my idea. This scripts does the handling of dynamic surebackup job and so on, but without a report of what was done within the job and thats the additional part I need. Otherwise I'm able to do these restore tests, but without an evidence that this was done :-)

thx
sandsturm
Egor Yakovlev
Veeam Software
Posts: 2537
Liked: 683 times
Joined: Jun 14, 2013 9:30 am
Full Name: Egor Yakovlev
Location: Prague, Czech Republic
Contact:

Re: SureBackup job with random VM through PowerShell

Post by Egor Yakovlev »

Make sure New-VBRSureBackupJobVerificationOptions has EnableEmailNotifications option enabled, that way SureBackup Job will send email report after each session.
/Thanks!
sandsturm
Veteran
Posts: 279
Liked: 23 times
Joined: Mar 23, 2015 8:30 am
Contact:

Re: SureBackup job with random VM through PowerShell

Post by sandsturm »

Hi Egor

Thanks for this info. I know the SureBackupJobVerificationOptions, but I don't need an email as output. I would need something else, a html file, csv file whatever. But email is the worst in my case :-) and this SureBackupJobVerificationOption has just email or snmp, but no output to file or something.

thx
sandsturm
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup job with random VM through PowerShell

Post by oleg.feoktistov »

Hi @sandsturm,

Here is an example of such an addition with some basic info from SureBackup task session saved in html report:

Code: Select all

$vsbSessionInfo = @()
$styleHtml = @"
        <style>
        TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
        TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #00FF00;}
        TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
        </style>
"@
$vsbSession = Get-VSBSession
$vsbTaskSessions = Get-VSBTaskSession -Session $vsbSession
foreach ($vsbTaskSession in $vsbTaskSessions) {
$vsbTaskSessionInfo = @{
    Name = $vsbTaskSession.Name
    JobName = $vsbTaskSession.JobName
    Status = $vsbTaskSession.Status
    StartTime = $vsbTaskSession.Info.StartTime
    FinishTime = $vsbTaskSession.Info.FinishTime
    PingStatus = $vsbTaskSession.PingStatus
    HeartbeatStatus = $vsbTaskSession.HeartbeatStatus
}
$vsbSessionInfo += $vsbTaskSessionInfo | select-object @{n='Name';e={$_.Name}}, @{n='Job Name';e={$_.JobName}}, @{n='Status';e={$_.Status}}, @{n='Start Time';e={$_.StartTime}}, @{n='Finish Time';e={$_.FinishTime}}, @{n='Ping Status';e={$_.PingStatus}}, @{n='Heartbeat Status';e={$_.HeartBeatStatus}}
$exportDir = test-path -path 'C:\Temp'
$exportTo = 'C:\Temp\SureBackupReport.html'
if (!$exportDir)
{
new-item -ItemType directory -Path 'C:\Temp'
$vsbSessionInfo | convertto-html -Head $styleHtml | out-file -filepath $exportTo -Append
write-host 'The report was saved to C:\Temp\SureBackupReport.html'-ForegroundColor Green
}
elseif ($exportDir){
write-host 'The report was saved to C:\Temp\SureBackupReport.html'-ForegroundColor Green
$vsbSessionInfo | convertto-html -Head $styleHtml | out-file -filepath $exportTo -Append
}
}
You need to play around with some variables and session parsing conditions to adjust it to your environment and maybe retrace some other info.
Add this code to your script and that should do the trick. The report is saved to C:\Temp\SureBackupReport.html

Hope that helps.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests