PowerShell script exchange
Post Reply
md@gmx.net
Novice
Posts: 5
Liked: never
Joined: Oct 18, 2019 2:00 pm
Full Name: Marcus Deubel
Contact:

SQL Server restore with powershell

Post by md@gmx.net »

Hi there,
is there a way to debug veeam powershell scripts?
I am trying to restore a sql server db to another server but I get always the error "Restore-VESQLDatabase : Failed to get access to <servername>."

Code: Select all

Add-PSSnapin VeeamPSSnapin
connect-vbrserver -server "veeamserver" -user 'veeamserver\veeamremoteuser' -password 'anything'
#Variables
$RestoreDate = Get-Date -format dd/MM/yyyy-HH:mm:ss
$ServerName = "sqlserver"
$InstanceName = " " # If you have default instance, use " "
$DatabaseName = "database"
$restorepoint = Get-VBRApplicationRestorePoint -SQL
$sessions = Start-VESQLRestoreSession -RestorePoint $restorepoint[$restorepoint.length-1]
$database = Get-VESQLDatabase -Session $sessions[0] -Name "database"
$dbfiles = Get-VESQLDatabaseFile -Database $database
#$restorepoint = Get-VBRApplicationRestorePoint -SQL
# Start-VESQLRestoreSession -RestorePoint $restorepoint[0]
$secpasswd = ConvertTo-SecureString 'passwordfortargetserver' -AsPlainText -Force
$oscreds = New-Object System.Management.Automation.PSCredential -ArgumentList 'sqlserver\administrator', $secpasswd
$secpasswd = ConvertTo-SecureString 'passwordforsqlserveruser' -AsPlainText -Force
$sqlcreds = New-Object System.Management.Automation.PSCredential -ArgumentList 'dbrestoreuser', $secpasswd
Restore-VESQLDatabase -Database $database -ServerName "sqlserver" -InstanceName " " -TargetFolder "S:\SQL Server Data" -force -GuestCredentials $oscreds -UseSQLAuthentication -SqlCredentials $sqlcreds -verbose
#Stop the connection
Disconnect-VBRServer | out-null
Any help is appriciated.

Regards
Marcus
chris.arceneaux
VeeaMVP
Posts: 695
Liked: 374 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: SQL Server restore with powershell

Post by chris.arceneaux »

Hi Marcus,

I reviewed your code and it looks good. I've got a couple comments and suggestions for you.

On your code:
  • InstanceName doesn't need to be specified unless the SQL instance isn't the default that you're restoring to.
  • ServerName is the destination server (not the source SQL server)
Suggestions on troubleshooting:

From the error you're getting, it seems that Veeam is unable to communicate or authenticate to the destination SQL server.
  • Please reference Veeam documentation and make sure the required connectivity is present. An OS firewall, an enterprise firewall, or network ACL might be blocking access.
  • Please make sure MS SQL is up and running on the destination server.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests