I executed this Powershell script to backup a Database, Drop that database and then restore it with a different name:
$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$res = new-object Microsoft.SqlServer.Management.Smo.Restore
$backup = new-object Microsoft.SqlServer.Management.Smo.Backup
$backup.Devices.AddDevice("D:\AWS_CM.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$backup.Database = "Arizona_CM"
$backup.Action = [Microsoft.SqlServer.Management.Smo.BackupActionType]::Database
$backup.Initialize = $TRUE
$backup.SqlBackup($srv)
$srv.Databases["Arizona_CM"].Drop()
$res.Devices.AddDevice("D:\AWS_CM.bak", [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$res.Database = "AWS_CM"
$res.NoRecovery = $TRUE
$res.SqlRestore($srv)
The script worked. However 10 minutes have passed and when I see the Database in SQL Server it is still in "Restoring" mode even though the size is only 80 mb.
Does anyone know how long restoring Database in SQL Server through powershell usually takes?
$res.NoRecovery = $TRUE
in query which means you restored databasewith NORECOVER
. You just need to log into SSMS and runrestore database db_name with recovery
and database will come online.