Created
January 31, 2017 07:35
-
-
Save Stuart-Moore/1215b9bba857a49430aab9243bb1557b to your computer and use it in GitHub Desktop.
Restore striped SQL Server backup from share using powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Written off the top of my head, check before relying on it. | |
import-module "SQLPS" -DisableNameChecking | |
$sqlsvr = New-Object -TypeName Microsoft.SQLServer.Management.Smo.Server("Server1") | |
$restore = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Restore | |
$devicetype = [Microsoft.SqlServer.Management.Smo.DeviceType]::File | |
$files=(Get-ChildItem \\YourServer\Yourshare\FULL\ -Filter *.bak | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-1)}) | |
foreach ($file in $files){ | |
$backupdevice = New-Object -TypeName Microsoft.SQLServer.Management.Smo.BackupDeviceItem($file.fullname,$devicetype) | |
$backups.Devices.Add($backupdevice) | |
} | |
$restore.Database = "YourDB" | |
$restore.ReplaceDatabase = $True | |
$restore.SQLRestore($sqlsvr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment