PowerShell script exchange
Post Reply
Tarandeep
Novice
Posts: 9
Liked: never
Joined: Mar 26, 2021 12:49 pm
Full Name: Tarandeep Singh
Contact:

Case #04983558: Start-VESQLRestoreSession not working

Post by Tarandeep »

Hi Team,
I had script to list out all the databases in sql backup job. Script was working well with veeam 10. However, it is not working well with the new powershell module in veeam 11.
I have been getting exception in command start-VESqlRestoreSession.
Error is mentioned in the screenshot below:
Image
HannesK
Product Manager
Posts: 14296
Liked: 2877 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by HannesK »

Hello,
and welcome to the forums.

The screenshot on the forums is not accessible for me. I looked in the support case and it looks like there is an issue with the IP address and earlier the script says "restore point not found".

Start-VESQLRestoreSession doesn't have any input for IP addresses... if you could copy & paste the relevant parts of the script and also the error, that would allow others to help.

Best regards,
Hannes
Tarandeep
Novice
Posts: 9
Liked: never
Joined: Mar 26, 2021 12:49 pm
Full Name: Tarandeep Singh
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by Tarandeep »

logs deleted
Start-VESQLRestoreSession : Object of type 'System.Net.IPAddress[]' cannot be converted to type 'System.String[]'.
Tarandeep
Novice
Posts: 9
Liked: never
Joined: Mar 26, 2021 12:49 pm
Full Name: Tarandeep Singh
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by Tarandeep »

Here is the script

Code: Select all

import-module Veeam.Backup.Powershell
function write-log
{	
Param( [parameter(Position=0)]
        [string] 
        $logEvent 
    , 
    [parameter(Position=1)]
    [ValidateSet("info","warning","success", "error")] 
        [string] 
        $type ="info"
    ) 
	$date = "$((get-date).tostring('yyyy-MM-dd HH:mm:ss'))"
    $colorHash = @{
        "info"="cyan";
        "warning"="yellow";
        "success"="green";
        "error"="red"

    }	
    $color = $colorHash.Item($type)
		Write-Host  "[$date] $type`:$logEvent" -ForegroundColor  $color
	
}

try {
    $data = @()
    $dbsProcessed = @{}
    


    Connect-VBRServer -Server $PlanTarget -User $HostUser -Password $HostUserAdminPass
    $jobs = Get-VBRJob | ?{$_.isbackup -eq $true}
    write-log "Jobs found $($jobs.count)"

        
    $jobs | ForEach-Object {
        write-log "fetching details for job $($_.name)"
        $job = $_
        $jobname= $_.name
        $state = "Ready"
        $jobBackup = Get-VBRBackup -Name $job.Name
       $dbsProcessed = @{}
        if($jobBackup -ne $null) {
       $jobBackup.GetObjectOibsAll() | ForEach-Object {
				$device = $_
        $deviceName=$_.Name
            write-log "Fetching dbs for device $($device.Name)"
            write-log "Fetching restore point [$($device.Name)]"
            $rp = Get-VBRRestorePoint -Backup $jobBackup -Name $device.Name |Sort-Object -Descending CreationTime | Select-Object -First 1
            if($rp -ne $null -and (Get-VBRApplicationRestorePoint -Id $rp.Id) -ne $null) {

                $appRestorePoint = Get-VBRApplicationRestorePoint -Id $rp.Id
                write-log "creating restore session [$($device.Name)]"
                $restoreSession = Start-VESQLRestoreSession -RestorePoint $appRestorePoint
                write-log "Restore session created [$($device.Name)]"
                $dbs = Get-VESQLDatabase -Session $restoreSession
                write-log "$($dbs.Count) Dbs found for device [$($device.Name)]"
                $dbs| ForEach-Object {
                    $dbKey = "$($_.serverName)_$($_.instanceName)_$($_.name)"
                    $obj = New-Object System.Object | select planName, deviceName, database, guid,state
                    $obj.PlanName = $job.Name
                    $obj.deviceName = $device.Name
                    $obj.database = $dbKey
                    $obj.state =$state
                    $obj.guid = "$($_.name)-$($device.ObjId.Guid)"
                    $data += $obj
                    }
                $restoreSession | Stop-VESQLRestoreSession -ErrorAction SilentlyContinue
            } else {
                Write-log "Restore point not found for device [$deviceName]" -type warning
            
                }
			

           }
        } else {
            write-log "not able to find dbs for job $($job.name)"
            write-log "No backup found for job $($job.name)" -type warning
        }
        

    }
    }catch{
    	$_
    }
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by oleg.feoktistov »

Hi Tarandeep,

Please refrain from posting logs in forum threads. We can get them from a support case.
I'll take time to review your script in my lab and come back with findings.

Thanks,
Oleg
Tarandeep
Novice
Posts: 9
Liked: never
Joined: Mar 26, 2021 12:49 pm
Full Name: Tarandeep Singh
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by Tarandeep »

Hi Oleg,
Is there any update ?
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by soncscy »

Just my input, you're doing tons of extra processing you don't need to in your script.

Code: Select all

       $jobBackup.GetObjectOibsAll() | ForEach-Object {
				$device = $_
        $deviceName=$_.Name
            write-log "Fetching dbs for device $($device.Name)"
            write-log "Fetching restore point [$($device.Name)]"
            $rp = Get-VBRRestorePoint -Backup $jobBackup -Name $device.Name |Sort-Object -Descending CreationTime | Select-Object -First 1
            if($rp -ne $null -and (Get-VBRApplicationRestorePoint -Id $rp.Id) -ne $null) {
Basically all of this can be removed and you can just parse on the RestorePoint object property HasSQL.

Code: Select all

PS C:\Users\Administrator\Desktop> $rp = Get-VBRRestorePoint -Backup $backup |sort -Property CreationTime -Descending
PS C:\Users\Administrator\Desktop> $rp.Hassql
False
True
True
This is a much better way of checking if a restore point should be passed to the Start-VESQLRestore session and it will reduce clutter in your code significantly.

I can't get your code to reproduce the issue in my lab environments, so my guess is you're somehow passing an object that breaks your validation and sends some invalid item, but it's not possible to tell with just the code you have.

Add in some debug lines before starting the VESQL session to post the object name, id, and maybe the object itself to console.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by oleg.feoktistov »

Hi Tarandeep,

Apologies for being away for a while. Like Harvey, I couldn't reproduce your issue in my lab. I did connect with the QA for assistance though and sent you a PM with the further information needed.

Thanks,
Oleg
Tarandeep
Novice
Posts: 9
Liked: never
Joined: Mar 26, 2021 12:49 pm
Full Name: Tarandeep Singh
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by Tarandeep »

My script seems to be working in other environment. May be issue was in my environment.
We are setting up a new lab. I think it will work fine there
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Case #04983558: Start-VESQLRestoreSession not working

Post by oleg.feoktistov »

It did look like the environment issue. Anyways, if you'll notice such exception when running this script in your new environment please send me the info I asked in PM. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests