PowerShell script exchange
Post Reply
DavidQbt
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2020 11:23 pm
Full Name: David Poza
Contact:

SureBackup PowerShell Script - Loop back and check current Backup Jobs running

Post by DavidQbt »

Hi All,

As the subject suggest, we currently have about 50 odd surebackup jobs which we just started testing and setting up. We run nightly backups of all of our VMs through backup jobs and we are wanting to utilize SureBackups during the day in order to check the backups that have run over night, so I started working on a script to try accomplish this, so far this is what I have gotten to, but unfortunately i am not very good when it comes to scripting and would like to see if anyone out there has tried something similar.

So this is what I have so far:

Add-PSSnapin VeeamPSSnapin
$sbuj01 = Get-VSBJob -name "XXXXXX1"
$sbuj02 = Get-VSBJob -name "XXXXXXXXXXX2"
$sbuj03 = Get-VSBJob -name "XXXXXXXXX3"
$sbuj04 = Get-VSBJob -name "XXXXXXXXX4"


Start-VSBJob $sbuj01
Start-VSBJob $sbuj02
#Start-VSBJob $sbuj03
#Start-VSBJob $sbuj04
#Start-VSBJob $sbuj05
#Start-VSBJob $sbuj06
#Start-VSBJob $sbuj07


So thats line by line, which essentially starts from the top and moves to the bottom - it seems to be smart enough to go through get the first backup job name then start the SureBackup, once completed it then moves on to the next line backupname/surebackup job and so on.

What I would like to accomplish is before it starts the job check if there is a Backup Job running, if there is a backup Job running wait X amount, after the wait, check again if there is no job running then continue on to running the surebackup and so on. Im guessing I am looking at a loopback of some sort here with Veeam powershell references to accomplish this, but have had no luck.

I went through the powershell reference but could not get my head around which would accomplish what I am looking for, so I am here seeking assistance for people who know a lot more than I do!

Is there a way to accomplish this? If so assistance would be appreciated. Or if you have any other suggestions to accomplish what I have mentioned will definitely be taken on board!

Thank you,

David.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup PowerShell Script - Loop back and check current Backup Jobs running

Post by oleg.feoktistov »

Hi David,

Even being a big fan of Powershell, I'd say it is redundant in this case as you can achieve quite the same within the UI:

1. Linking backup job to a SureBackup job.
2. Leveraging 'Wait for backup jobs' option on Job Schedule step of SureBackup Job Wizard.

Thus, primarily to triggering SureBackup job, VBR will check if linked backup jobs are still running and, if they are, await for up to the time specified.

Best regards,
Oleg
DavidQbt
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2020 11:23 pm
Full Name: David Poza
Contact:

Re: SureBackup PowerShell Script - Loop back and check current Backup Jobs running

Post by DavidQbt »

Hi Oleg,

Thank you very much for the response.

I know of the way you have explained there, but I believe that would run the SureBackup right after the linked backup is done (or after the wait period set in the scheduled set). But what we would like to attempt is to do all SureBackups after all of the backups are done.

Out Backups are run nightly and take the whole night, and we would like the SureBackups to run during the day. If we add the SureBackups during the Backup process it will likely prolong the process to go into the day which we rather not do as there is high activity on all of the VMs during the day (just precautions we have taken for a number of years).

So we were hoping to have the script check on any active backup job and if there isn't any running then start the process and so on,but after there is no backups running. And keep on checking during the day until night time.

But if there is no way to do this is fine. We'll adjust accordingly I suppose.

Regards,

David.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup PowerShell Script - Loop back and check current Backup Jobs running

Post by oleg.feoktistov » 2 people like this post

Hi David,
I know of the way you have explained there, but I believe that would run the SureBackup right after the linked backup is done (or after the wait period set in the scheduled set).
It would start at a time you specified in job schedule settings and wait if any linked jobs are running in case this option is checked.
But it would still wait for linked jobs only.

So, based on your use case, I wrote the function below:

Code: Select all

asnp VeeamPSSnapin
function Start-VSBJobAfterBackup {
[CmdletBinding()]
param(
    [Parameter(
        Position = 0,
        Mandatory = $true
    )]
    [Veeam.Backup.Core.SureBackup.CSbJob[]]$Job,
    [int]$Retries,
    [int]$WaitSec

)
$Count = 0
$success = $null

do {
    try {
       $sessions = Get-VBRBackupSession | where {$_.State -ne 'Stopped'}
       if ($sessions -eq $null) {
        $sbJobs = $Job
        foreach ($sbJob in $sbJobs) {
            write-host 'Starting '$sbJob
            Start-VSBJob -Job $sbJob
        }
        $success = $true
       }
       elseif ($sessions -ne $null) {
            write-host 'Some backup jobs are still running. Sleeping for'$waitSec 'seconds'
            Start-Sleep -Seconds $waitSec
            $Count += 1
            write-host 'Retry '$Count
       }
}
catch {
    throw $_.Exception
}
}
until ($Count -eq $Retries -or $Success)
}
You can also find this script and its full usage information on my GitHub page.

Hope that helps,
Oleg
DavidQbt
Novice
Posts: 3
Liked: never
Joined: Apr 21, 2020 11:23 pm
Full Name: David Poza
Contact:

Re: SureBackup PowerShell Script - Loop back and check current Backup Jobs running

Post by DavidQbt »

Hi Oleg,

Perfect, thank you very much. I will give that a go and report back on my results.

Regards,

David.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests