-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 03, 2020 8:41 pm
- Full Name: Marios Philippopoulos
- Contact:
How to "catch" Get-VBRApplicationRestorePoint errors
Hi,
We are using Get-VBRApplicationRestorePoint to get app-aware restore points for SQL Server from a bunch of VMs.
We are getting the following error:
...
Get-VBRApplicationRestorePoint : A restore point VMName1 does not exist
Anyone have TRY/CATCH code for this sort of error?
Thanks,
Marios
We are using Get-VBRApplicationRestorePoint to get app-aware restore points for SQL Server from a bunch of VMs.
We are getting the following error:
...
Get-VBRApplicationRestorePoint : A restore point VMName1 does not exist
Anyone have TRY/CATCH code for this sort of error?
Thanks,
Marios
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi Marios,
Can you, please, elaborate on what you are trying to achieve with error handling in your case?
Do you want a custom message displayed if this particular error is thrown or else?
Thanks,
Oleg
Can you, please, elaborate on what you are trying to achieve with error handling in your case?
Do you want a custom message displayed if this particular error is thrown or else?
Thanks,
Oleg
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 03, 2020 8:41 pm
- Full Name: Marios Philippopoulos
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi Oleg,
We are using the Get-VBRApplicationRestorePoint command inside a loop that cycles through a list of servers/databases and records the latest restore point for each.
We want to be able to log the error in a database table and continue on to the next server in the loop.
Also display the error (or a custom message) on the script output.
Thanks,
Marios
We are using the Get-VBRApplicationRestorePoint command inside a loop that cycles through a list of servers/databases and records the latest restore point for each.
We want to be able to log the error in a database table and continue on to the next server in the loop.
Also display the error (or a custom message) on the script output.
Thanks,
Marios
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
The syntax of writing it to a database would depend on database type. You can take a look at Invoke-SqlCmd if it involves SQL server.
When it comes to try/catch construction, the script below would write a full error message to a file and throw custom error to the console output:
Thanks,
Oleg
When it comes to try/catch construction, the script below would write a full error message to a file and throw custom error to the console output:
Code: Select all
try {
$rp = Get-VBRApplicationRestorePoint -Name 'VeeamSQL'
Start-VESQLRestoreSession -RestorePoint $rp
}
catch {
if ($_.CategoryInfo.Category -eq 'InvalidData') {
$_ > "C:\data.log"
throw 'Invalid data passed'
}
}
Oleg
-
- Novice
- Posts: 5
- Liked: never
- Joined: Jul 03, 2020 8:41 pm
- Full Name: Marios Philippopoulos
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Thank you! Will give that a try.
-
- Novice
- Posts: 5
- Liked: never
- Joined: Feb 11, 2021 12:00 pm
- Full Name: Anil Babu
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi All... We are using below ps script and it's working fine but if we getting any error , Try-Catch function is not collecting the actual error .
Code: Select all
$VMName="xxxxxxx"
$FilterHours="24"
function Run-SQLRestorePointReport {
begin
{
$Username="xxxxx"
$password=Get-Content "D:\password.txt"
$VBRServer = "xxxxx" #mention servername
Add-PSSnapin VeeamPsSnapin
$Vemmconn = Connect-VBRServer -Server $VBRServer -User $Username -Password $password
Add-PSSnapin "VeeamPSSnapIn" -ErrorAction SilentlyContinue
}
process {
try
{
if ($VMName -AND $FilterHours) {
$SQLRPs = Get-VBRApplicationRestorePoint -Name $VMName -SQL | Where-Object { $_.CreationTime -ge ((Get-Date).AddHours(-$FilterHours)) }
}
elseif ($VMName) {
$SQLRPs = Get-VBRApplicationRestorePoint -Name $VMName -SQL
}
elseif ($FilterHours) {
$SQLRPs = Get-VBRApplicationRestorePoint -SQL | Where-Object { $_.CreationTime -ge ((Get-Date).AddHours(-$FilterHours)) }
}
else {
$SQLRPs = Get-VBRApplicationRestorePoint -SQL
}
}
Catch
{
Write-Output ($_.Exception.Message)
}
}
}
Disconnect-VBRServer
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi Anil,
Not all errors are passed to catch part by default. If the error is non-terminating, you need to tell powershell to pass it to catch and treat it as terminating. It can be done by setting $ErrorActionPreference = Stop in the beginning of your script.
Thanks,
Oleg
Not all errors are passed to catch part by default. If the error is non-terminating, you need to tell powershell to pass it to catch and treat it as terminating. It can be done by setting $ErrorActionPreference = Stop in the beginning of your script.
Thanks,
Oleg
-
- Veeam Vanguard
- Posts: 282
- Liked: 113 times
- Joined: Apr 20, 2017 4:19 pm
- Full Name: Joe Houghes
- Location: Castle Rock, CO
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
It's actually better to set the ErrorAction parameter to 'Stop' for each cmdlet being run (within each if/elseif block), since this is a function containing that code.
Setting ErrorActionPreference may not pass that in & out of each scope properly.
Setting ErrorActionPreference may not pass that in & out of each scope properly.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Agree with Joe here.
-
- Novice
- Posts: 5
- Liked: never
- Joined: Feb 11, 2021 12:00 pm
- Full Name: Anil Babu
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Thank you Oleg/Joe. Will try on this .
-
- Novice
- Posts: 5
- Liked: never
- Joined: Feb 11, 2021 12:00 pm
- Full Name: Anil Babu
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi Oleg/Joe.... I have implemented your suggestions and now Try-Catch function is collecting the actual error . but If we include function Run-SQLRestorePointReport { Try-Catch function not collecting the actual error.
Code: Select all
$VMName="XXXXXX"
$FilterHours="24"
#function Run-SQLRestorePointReport {
$Username="XXXXXX"
$password=Get-Content "D:\password.txt"
$VBRServer = "XXXXXX" #mention servername
Add-PSSnapin VeeamPsSnapin
$Vemmconn = Connect-VBRServer -Server $VBRServer -User $Username -Password $password
$ErrorActionPreference = 'Stop'
try {
if ($VMName -AND $FilterHours) {
$SQLRPs = Get-VBRApplicationRestorePoint -Name $VMName -SQL | Where-Object { $_.CreationTime -ge ((Get-Date).AddHours(-$FilterHours)) }
}
}
catch {
Write-Output ($_.Exception.Message)
}
Disconnect-VBRServer
Output:
A restore point XXXXXX does not exist
-
- Veeam Software
- Posts: 2010
- Liked: 670 times
- Joined: Sep 25, 2019 10:32 am
- Full Name: Oleg Feoktistov
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Hi Anil,
Like Joe suggested above, set error action parameter for each cmdlet being run instead. The syntax is:
Any cmdlet should support this common parameter.
Thanks,
Oleg
Like Joe suggested above, set error action parameter for each cmdlet being run instead. The syntax is:
Code: Select all
Get-VBRApplicationRestorePoint -Name $VMName -SQL -ErrorAction Stop
Thanks,
Oleg
-
- Novice
- Posts: 5
- Liked: never
- Joined: Feb 11, 2021 12:00 pm
- Full Name: Anil Babu
- Contact:
Re: How to "catch" Get-VBRApplicationRestorePoint errors
Thanks Oleg. It's working now.
Who is online
Users browsing this forum: No registered users and 8 guests