Backup and Recovery in MS SQL Server Andrea Imrichová
Types of Backups copy-only backup database backup differential backup full backup log backup file backup partial backup
Copy-Only Backups without affecting the overall backup and restore procedures for the database recorded in the is_copy_only column of the backupset table.
Database backup represent the whole database at the time the backup finished.
Differential backup only the data extents that have changed in the filegroups since the previous partial backup, known as the base for the differential.
Full backup contains all the data in a specific database Partial backup data from only some of the filegroups
Backup devices backup disk media set physical backup device maximum size free disk space backup disk - different than the database data and log disks
Specifying a Backup File by Using its Physical Name BACKUP DATABASE database_name TO DISK = { 'physical_backup_device_name' @physical_backup_device_name_var } BACKUP DATABASE AdventureWorks2012 GO TO DISK = 'Z:\SQLServerBackups\AdventureWorks2012.bak'; --------- RESTORE { DATABASE LOG } database_name FROM DISK = { 'physical_backup_device_name' @physical_backup_device_name_var }
Backing Up to a File on a Network Share permissions needed to read/write Universal Naming Convention (UNC) \\Systemname\ShareName\Path\FileName BACKUP DATABASE AdventureWorks2012 TO DISK = '\\BackupSystem\BackupDisk1\AW_backups\AdventureWorksData.Bak'; GO
Logical backup device user-defined name points to a specific physical backup device must be unique sys.backup_devices - to view the existing logical device names BACKUP DATABASE AdventureWorks2012 GO TO AdventureWorksBackups;
Mirrored Backup Media Sets increases the reliability of backups by providing redundancy damaged ->no longer usable mirrored media: 2-4 mirrors
Backup Compression From SQL Server 2014 Compressed and uncompressed backups cannot coexist in a media set. low-priority compressed backups - Resource Governor backup_size:compressed_backup_size Factors: type of data, consistency of the data, encryption, if its compressed SELECT backup_size/compressed_backup_size FROM msdb..backupset;
Media Families Backups created on a single nonmirrored device or a set of mirrored devices in a media set Each disk/tape - media sequence number
Media header Contained in backup media Informations: Name, sequence number of the media family, unique vendor identification number, etc. Standard backup format Microsoft Tape Format(MTF)
Backup Sets successful backup operation adds a single backup set to the media set. backup media (only one media family) entire backup set (multiple media families) backup distributed
BACKUP DATABASE AdventureWorks2012 TO TAPE = '\\.\tape0', TAPE = '\\.\tape1', TAPE = '\\.\tape2 WITH FORMAT, MEDIANAME = 'MyAdvWorks_MediaSet_1'
The number of backup media in a media set depends on several factors: Number of backup devices Type of backup devices Number of backup sets
Creating a New Media Set format the backup media Changes in the backup media: 1. deletes the old header (if any) 2. deletes all previous contents of the currently mounted tape 3. writes a new media header
Backing Up to an Existing Media Set 1. Append to the existing backup set. 2. Overwrite all existing backup sets with the current backup, leaving the current media header in place.
Appending to Existing Backup Sets default Backups performed at different times from the same or different databases only at the end
Overwriting Backup Sets is specified by using the INIT option preserve the media header, if any Backup media is not overwritten if: The existing backups on the media have not expired (SKIP) The media name, if provided, does not match the name on the backup media.
Restore and Recovery Overview The database (a complete database restore) The data file (a file restore) The data page (a page restore)
Recovery Models designed to control transaction log maintenance is a database property Three recovery models exist: simple, full, and bulk-logged A database can be switched to another recovery model at any time
Simple recovery model Requires no log backups Automatically reclaims log space to keep space requirements small Operations that require transaction log backups are not supported Cannot be used: Log shipping AlwaysOn or Database mirroring Media recovery without data loss Point-in-time restores
Full recovery model Requires log backups. No work is lost due to a lost or damaged data file. Can recover to an arbitrary point in time
Bulk logged recovery model Requires log backups. An adjunct of the full recovery model Reduces log space usage by using minimal logging If the log is damaged or bulk-logged operations occurred since the most recent log backup changes redone
Restore scenarios Complete database restore File restore Page restore Piecemeal restore
SQL Server backup cannot be restored by a version of SQL Server that is older than the version that created the backup. The Database Recovery Advisor