PowerShell script exchange
Post Reply
manuel.aigner
Enthusiast
Posts: 31
Liked: 5 times
Joined: Sep 25, 2017 8:25 am
Full Name: Manuel Aigner
Contact:

Restore-VESQLDatabase -> 'System.Exception: Object reference not set to an instance of an object.'

Post by manuel.aigner »

Hi there,

Since one or two weeks one of my restore scripts isn't working any more. I haven't changed any thing since months in this script frame work.


Here a strongly shortened part, for easier understanding what I'm doing in script/module

Code: Select all

# Find Restore point with separate function
function Get-SQLBackup {
	$rpStep1 = Get-VBRApplicationRestorePoint -SQL -Name $vmName -ErrorAction Stop

	# ... filter by creation date
	$myCreationDate = get-date -Date (get-date).AddDays($stepsBackward * -1) -Format "dd.MM.yyyy"
	$rpSQL = ($rpStep1 | where { (Get-Date -Date $_.creationtime -Format "dd.MM.yyyy") -eq $myCreationDate } | select -First 1)
	return $rpSQL
}

$rpSQL = Get-SQLBackup -vmName $vmName -stepsBackward $stepsBackward
$MyRestoreSession = Start-VESQLRestoreSession -RestorePoint $rpSQL.rpsql -ErrorAction Stop
$MyDB2Restore = Get-VESQLDatabase -Session $MyRestoreSession -Name $databasename -ErrorAction Stop | where { $_.InstanceName -eq $sourceInstance }
$MyDestinationDBFiles = Get-SQLServerDataPaths -ServerName $destinationServer -InstanceName $destinationInstance -Credential $destinationCredential # this function returns correct Data/Log Paths for destination instance

$paraRestoreVESQLDatabase = @{
		Database		 = $MyDB2Restore
		ServerName	     = $destinationServer # from script param
		InstanceName	 = $destinationInstance # from script param
		DatabaseName	 = $destinationDatabaseName # from script param
		GuestCredentials = $destinationCredential # from script param fetched from password vault
		SqlCredentials   = $destinationCredential # from script param fetched from password vault
		File			 = $MySourceDBFiles
		TargetPath	     = $DBFilePaths
		Force		     = $force
		ErrorAction	     = 'Stop'
	}

$resRestore = Restore-VESQLDatabase @paraRestoreVESQLDatabase
...

After adding some debug code, I'm sure all relevant params for Restore-VESQLDatabase are filled as expected.

Code: Select all

Key   : Database
Value : DWH_SOURCE_mtl - SQLINSTANCE1
Name  : Database

Key   : TargetPath
Value : {R:\MSSQL13.SQLINSTANCE1\MSSQL\DATA\DWH_SOURCE_mtl.mdf, S:\MSSQL13.SQLINSTANCE1\MSSQL\DATA\DWH_SOURCE_mtl_log.ldf}
Name  : TargetPath

Key   : ServerName
Value : <masked>
Name  : ServerName

Key   : InstanceName
Value : SQLINSTANCE1
Name  : InstanceName

Key   : DatabaseName
Value : DWH_SOURCE_mtl
Name  : DatabaseName

Key   : SqlCredentials
Value : System.Management.Automation.PSCredential
Name  : SqlCredentials

Key   : Force
Value : True
Name  : Force

Key   : GuestCredentials
Value : System.Management.Automation.PSCredential
Name  : GuestCredentials

Key   : ErrorAction
Value : Stop
Name  : ErrorAction

Key   : File
Value : {R:\MSSQL13.SQLINSTANCE1\MSSQL\DATA\DWH_SOURCE_mtl.mdf, S:\MSSQL13.SQLINSTANCE1\MSSQL\DATA\DWH_SOURCE_mtl_log.ldf}
Name  : File
also the requested restore point can be found and the returned object seems to be ok. Otherwise my script will terminate due to automatic plausi checking with error.

Are there any suggestions?
PetrM
Veeam Software
Posts: 3264
Liked: 528 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Restore-VESQLDatabase -> 'System.Exception: Object reference not set to an instance of an object.'

Post by PetrM »

Hi Manuel,

This is a common .Net exception which is thrown when you try to get a property or call a method of NULL object. I'd suggest to open a support case and ask our support engineers to analyze debug logs to understand what can cause such an issue. Please don't forget to share a support case ID with us.

Thanks!
manuel.aigner
Enthusiast
Posts: 31
Liked: 5 times
Joined: Sep 25, 2017 8:25 am
Full Name: Manuel Aigner
Contact:

Re: Restore-VESQLDatabase -> 'System.Exception: Object reference not set to an instance of an object.'

Post by manuel.aigner »

Good Morning Petr,
thanks for reply. Ok I've opened a case -> Case # 04887015.

Strange thing is, I can't find any actual powershell logs inside %programdata%\Veeam\...
The latest ones are from April :/
PetrM
Veeam Software
Posts: 3264
Liked: 528 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Restore-VESQLDatabase -> 'System.Exception: Object reference not set to an instance of an object.'

Post by PetrM »

Hi Manuel,

It should be there: C:\Users\Administrator\AppData\Local\Veeam\Backup. Also, you may try to export all logs from the backup server as per the instructions of this KB.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests