Created
July 22, 2016 10:04
-
-
Save Alex-Yates/efbf9e6be2b65d85bfde3367cf4cafd4 to your computer and use it in GitHub Desktop.
DLM Automation PS scripts: Restore Prod DB over Acceptance DB (run before dry run deployments)
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
param | |
( | |
[Parameter(Mandatory=$true)] | |
[string]$ProductionDB = $null, | |
[Parameter(Mandatory=$true)] | |
[string]$AcceptanceDB = $null, | |
[Parameter(Mandatory=$true)] | |
[string]$DatabaseServer = $null | |
) | |
$ErrorActionPreference = "Stop" | |
Invoke-Sqlcmd -Query "EXECUTE master..sqlbackup '-SQL ""BACKUP DATABASE [$ProductionDB] TO DISK = ''C:\backups\<AUTO>.sqb'' WITH COMPRESSION = 3""'" -ServerInstance $DatabaseServer -AbortOnError | |
Invoke-Sqlcmd -Query "EXECUTE master..sqlbackup '-SQL ""RESTORE DATABASE [$AcceptanceDB] FROM DISK = ''C:\Backups\*.sqb'' SOURCE = ''$ProductionDB'' LATEST_FULL WITH RECOVERY, DISCONNECT_EXISTING, MOVE ''$ProductionDB'' TO ''C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\$AcceptanceDB.mdf'', MOVE ''$($ProductionDB)_log'' TO ''C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\$($AcceptanceDB)_log.ldf'', REPLACE""'" -ServerInstance $DatabaseServer -AbortOnError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment