Skip to content

Commit

Permalink
Update restoreBackup.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
raczeja authored Nov 28, 2024
1 parent abbc172 commit 26ffaee
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion restoreBackup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ docker exec -i "sqlserver-container" mkdir "/var/opt/mssql/backup"
Write-Output "copy ./docker/AdventureWorks2008R2FullDatabaseBackup.bak to /var/opt/mssql/backup"
docker cp "./docker/AdventureWorks2008R2FullDatabaseBackup.bak" sqlserver-container:/var/opt/mssql/backup
Write-Output "restore backup"
$count = 0
do
{
$JSON=docker inspect --format='{{json .State.Health}}' sqlserver-container | Out-String | ConvertFrom-Json
Write-Host HEALTHCHECK: $JSON.Status.ToString() sqlserver-container
Start-Sleep -s 10
$count++
docker ps -a
if ($count -gt 10) {
Write-Host "Loop terminated after 10 iterations."
break
}
}
Until ($JSON.Status.ToString() -eq 'healthy')
docker exec -i sqlserver-container /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "yourStrong22Password" `
-Q "RESTORE DATABASE AdventureWorks2008R2 FROM DISK = '/var/opt/mssql/backup/AdventureWorks2008R2FullDatabaseBackup.bak' `
WITH MOVE 'AdventureWorks2008R2_Data' TO '/var/opt/mssql/data/AdventureWorks2008R2.mdf', `
MOVE 'AdventureWorks2008R2_Log' TO '/var/opt/mssql/data/AdventureWorks2008R2_1.LDF'"
MOVE 'AdventureWorks2008R2_Log' TO '/var/opt/mssql/data/AdventureWorks2008R2_1.LDF'"

0 comments on commit 26ffaee

Please sign in to comment.