Created
January 15, 2019 22:11
-
-
Save OsirisDBA/3e55393096dc2c1ac464535bfad87291 to your computer and use it in GitHub Desktop.
Restore and DBCC testing with dbatools
This file contains hidden or 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
import-module dbatools | |
$CMSInstance = "MyCMSInst" | |
$Test2014Instance = "SQL2014" | |
$Test2017Instance = "SQL2017" | |
$InventoryInst = "MYINV" | |
$InventoryDB = "DBATools" | |
$InventoryTable = "BackupTestResults" | |
Enum SQLVersionMajor { | |
SQL2019 = 15 | |
SQL2017 = 14 | |
SQL2016 = 13 | |
SQL2014 = 12 | |
SQL2012 = 11 | |
SQL2008 = 10 | |
SQL2005 = 9 | |
} | |
Get-DbaCmsRegServer -SqlInstance $CMSInstance | | |
Foreach-Object { | |
Write-Host $_ | |
$Version = (get-DbaInstanceProperty -SqlInstance $_ -InstanceProperty "VersionMajor").Value | |
If ( $Version -eq [SQLVersionMajor]::SQL2014 ` | |
-Or $Version -eq [SQLVersionMajor]::SQL2012 ` | |
-Or $Version -eq [SQLVersionMajor]::SQL2008 ` | |
-Or $Version -eq [SQLVersionMajor]::SQL2005 ` | |
) { | |
$DestInstance = $Test2014Instance | |
Test-DbaLastBackup -SqlInstance $_ ` | |
-Destination $DestInstance ` | |
-Prefix test_ ` | |
-ExcludeDatabase master | | |
select * ` | |
, @{name="RestoreSeconds";expression={ (New-TimeSpan -Start $_.RestoreStart -End $_.RestoreEnd).TotalSeconds} },@{name="DBCCSeconds";expression={ (New-TimeSpan -Start $_.DBCCStart -End $_.DBCCEnd).TotalSeconds }} | | |
select * -ExpandProperty Size | | |
select SourceServer, TestServer, Database, FileExists, @{Name="SizeKB";Expression={$_.Kilobyte}}, RestoreResult, RestoreStart, RestoreEnd, RestoreSeconds, DbccResult, DbccStart, DbccEnd, DbccSeconds | | |
Write-DbaDataTable -SqlInstance $InventoryInst -Database $InventoryDB -Table $InventoryTable | |
} | |
else { | |
$DestInstance = $Test2017Instance | |
Test-DbaLastBackup -SqlInstance $_ ` | |
-Destination $DestInstance ` | |
-Prefix test_ ` | |
-ExcludeDatabase master | | |
select * ` | |
, @{name="RestoreSeconds";expression={ (New-TimeSpan -Start $_.RestoreStart -End $_.RestoreEnd).TotalSeconds} },@{name="DBCCSeconds";expression={ (New-TimeSpan -Start $_.DBCCStart -End $_.DBCCEnd).TotalSeconds }} | | |
select * -ExpandProperty Size | | |
select SourceServer, TestServer, Database, FileExists, @{Name="SizeKB";Expression={$_.Kilobyte}}, RestoreResult, RestoreStart, RestoreEnd, RestoreSeconds, DbccResult, DbccStart, DbccEnd, DbccSeconds | | |
Write-DbaDataTable -SqlInstance $InventoryInst -Database $InventoryDB -Table $InventoryTable | |
} | |
} | |
Write-Host "Complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment