I want to restore the same database every day on a test server.
I think my code is correct, however I keep getting an error "Server was not found or not accessible"
Below is my code to get a sql backup database + restorepoint.
Code: Select all
#add snapin and connect to server
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
connect-vbrserver -server "xxxxxxx" #-user <domainname\username or servername\username> -password <password>
#Variables
$RestoreDatum = Get-Date -format dd/MM/yyyy-HH:mm:ss
$ServerName = "yyyyyyy"
$InstanceName = "MSSQLSERVER" # it's default instance, but with or without this, doesn't work
$DatabaseName = "the_database_name"
$DatabaseNameNew = "$($DatabaseName) $($RestoreDatum)"
#OS and SQL Credentials
$guestcreds = Get-VBRCredentials -Name "xxx\ServiceACCVeeam"
$sqlcreds = Get-VBRCredentials -Name "xxx\ServiceACCVeeam"
#The $Restore variable contains the correct data
$Restore = Get-VBRApplicationRestorePoint -id 5d8516b2-7bcc-484f-b402-56224c54e625
#The $DBRestorePoint variable contains the correct data
$DBRestorePoint = Get-VBRSQLDatabase -ApplicationRestorePoint $Restore -Name $DatabaseName
Start-VBRSQLDatabaseRestore -Database $DBRestorePoint -ServerName $ServerName -DatabaseName $DatabaseNameNew -GuestCredentials $guestcreds -SqlCredentials $sqlcreds -Wait
#Stop the connection
Disconnect-VBRServer | out-null
Errorcode:
Start-VBRSQLDatabaseRestore : SQL server validation failed: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 -
Error Locating Server/Instance Specified)
At line:21 char:1
+ Start-VBRSQLDatabaseRestore -Database $DBRestorePoint -ServerName $ServerName -D ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-VBRSQLDatabaseRestore], Exception
+ FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Cmdlets.StartVBRSQLDatabaseRestore
Any known bugs? Am I doing anything wrong here?
Thanks for the help.