I trial to make a script to make at auto restoret of a test sql database.
Is works in Powershell ISE. Is not work in Powershell
I get this error:
Code: Select all
Restore-VESQLDatabase : File does not exist. File: [].
Failed to open storage for read access. Storage: [].
Failed to restore file from local backup. VFS link: [summary.xml]. Target file: [MemFs://frontend::CDataTransferCommand
Set::RestoreText_{703999c0-ebc7-49b2-a580-eebcc98052cc}]. CHMOD mask: [0].
Agent failed to process method {DataTransfer.RestoreText}.
At C:\Script\Auto-restore.ps1:34 char:1
+ Restore-VESQLDatabase -Database $database -databasename "SQL_ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Restore-VESQLDatabase], Exception
+ FullyQualifiedErrorId : System.Exception,Veeam.SQL.PowerShell.RestoreVESQLDatabaseCmdlet
Code: Select all
#add veeam powershell addin
Add-PSSnapin -Name VeeamPSSnapIn
#Get restor point
$restorepoint = Get-VBRApplicationRestorePoint -SQL -Name "SQL1"| Sort-Object –Property CreationTime –Descending | Select-Object -First 1
#Start restore service
Start-VESQLRestoreSession -RestorePoint $restorepoint
#Set session id in variabel
$session = Get-VESQLRestoreSession
#Set Datebase variable need to restore
$database = Get-VESQLDatabase -Session $session[0] -Name "SQL_Prod"
#Show settinges for restore
write-host "session: $session"
write-host "database: $database"
write-host "restorepoint: $restorepoint"
#set login
$username = "Username for SQL Restore"
$pwdTxt = Get-Content "File location for password"
$securePwd = $pwdTxt | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
#Get datebase
$files = Get-VESQLDatabaseFile -Database $database
#$files
# Path Type
# D:\SQL_DBs\erp.mdf Primary
# C:\SQL\LOGs\erp_log.ldf Secondary
#
#Set filer place
$path = @("E:\Data\SQL_Test_DATA.mdf","F:\LOG\SQL_Test_LOG.ldf","E:\Data\SQL_Test_1_DATA.ndf","E:\Data\SQL_Test_2_DATA.ndf","E:\SQL_DK_2018_Test_3_DATA.ndf","E:\Data\SQL_Test_4_DATA.ndf","E:\Data\SQL_Test_5_DATA.ndf","E:\Data\SQL_Test_6_DATA.ndf","E:\SQL_Test_7_DATA.ndf")
#run restore
Restore-VESQLDatabase -Database $database -databasename "SQL_Test" -ServerName "SQLserver FQDN" -File $files -TargetPath $path -SqlCredentials $cred -Force
#Stop Restore service
Stop-VESQLRestoreSession -Session $session[0]
best regard Uffe