PowerShell script exchange
Post Reply
NovemberBlues
Lurker
Posts: 1
Liked: never
Joined: Apr 27, 2018 7:54 am
Full Name: James Smith
Contact:

Veeam SQL Powershell Script - Restore Point Dismounting

Post by NovemberBlues »

Hi;

I'm looking to utilise veeam to restore specific databases from one sql servers backup on to many other sql servers.

I have a script which works but is slower than it should be really as it has to keep mounting and dismounting the restore point due to the way the script is written. Is there any way to keep the restore point mounted and pass through the database and destination details?

Below is the current script;

Add-PSSnapin VeeamPSSnapIn -ErrorAction SilentlyContinue

$DBIMPORT = Import-Csv C:\temp\devdbs.csv
foreach ($entry in $DBIMPORT) {
$db = $entry.DevelopmentDatabases

write-host Restoring $db to server -ForegroundColor Green

$source_job_name = "BR - Development and Test"
$source_vm = "server"
$source_db_name = $db

$target_vm = "server1"
$target_credentials = Get-VBRCredentials -Name "domain\veeam.user"
#$target_instance = "localhost"

$target_database = $source_db_name

$restore_point = Get-VBRRestorePoint -Backup $source_job_name | ? VmName -match "^$source_vm" | Sort-Object creationtime -Descending | Select-Object -First 1

try {
$database = Get-VBRSQLDatabase -ApplicationRestorePoint $restore_point -Name $source_db_name
} catch {
"Couldnt find database"
break
}
$starttime = Get-Date
write-host $database started restoring at $starttime -ForegroundColor White
$restore_session = Start-VBRSQLDatabaseRestore -Database $database -ServerName $target_vm -Databasename $target_database -GuestCredentials $target_credentials -SqlCredentials $target_credentials -Force -Wait
$endtime = Get-Date
Write-host $database finished restoring at $endtime -ForegroundColor Blue}
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests