This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
computing:windows:mssql_backup [2012/01/20 22:05] gcooper |
computing:windows:mssql_backup [2022/02/10 07:42] (current) gcooper |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Microsoft SQL Server Backup ====== | ====== Microsoft SQL Server Backup ====== | ||
- | ===== Database Recovery Models ===== | + | **SQL Backup Background**: |
+ | **Download SQL Server Management Studio**: https:// | ||
+ | <note tip>In general, it is **simpler and easier to restore a complete backup** (single file) than a differential or log backup (multiple file). | ||
+ | |||
+ | ===== Database Restore ===== | ||
+ | |||
+ | **[[https:// | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | <note tip>It is convenient to use the **Microsoft SQL Server Management Studio** to perform the actual database recovery.</ | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | ==== MSSQL Management Studio ==== | ||
+ | |||
+ | **Restore a Database Backup Using SSMS**: https:// | ||
+ | |||
+ | ==== Transact-SQL ==== | ||
+ | |||
+ | |RESTORE DATABASE database_name FROM full_database_backup WITH NORECOVERY |complete database backup | ||
+ | |RESTORE DATABASE database_name FROM differential_backup WITH NORECOVERY | ||
+ | |RESTORE DATABASE database_name FROM log_backup WITH NORECOVERY | ||
+ | |RESTORE DATABASE database_name FROM log_backup WITH NORECOVERY | ||
+ | |... |in chronological order | | ||
+ | |RESTORE DATABASE database_name FROM log_backup WITH NORECOVERY | ||
+ | |RESTORE DATABASE database_name WITH RECOVERY | ||
+ | |||
+ | ===== Database Recovery Models ===== | ||
==== Script ==== | ==== Script ==== | ||
- | Set all databases to the Full recovery model: | + | Set all databases to the FULL recovery model. Replace the three occurrences of " |
< | < | ||
Line 30: | Line 58: | ||
WHILE @@FETCH_STATUS = 0 | WHILE @@FETCH_STATUS = 0 | ||
BEGIN | BEGIN | ||
- | IF (SELECT DATABASEPROPERTYEX(@dbname,' | + | IF (SELECT DATABASEPROPERTYEX(@dbname,' |
-- create the alter database command for each database | -- create the alter database command for each database | ||
- | SET @cmd = 'ALTER DATABASE "' | + | SET @cmd = 'ALTER DATABASE "' |
- | -- alter each dataabase | + | -- alter each database |
EXEC(@cmd) | EXEC(@cmd) | ||
PRINT @dbname | PRINT @dbname | ||
- | end | + | END |
FETCH NEXT FROM db_recovery_cursor INTO @dbname | FETCH NEXT FROM db_recovery_cursor INTO @dbname |