12. Backups and Restores

ALTER DATABASE db SET RECOVERY SIMPLE|FULL|BULK_LOGGED;

Full backup in any recovery model does:

Differential backup:

TAPE backup deprecated

Backup device

Media

Logical Backup Device sp_adddumpdevice

Media Set: Each media family has:

Backup Set - append/overwrite media

Backup Strategies

Copy only backup is not entered into restore sequence. Does not reset for differential backup. No copy - only differential backup.

Can do copy-only transaction logs backup:

‘Perform Checksum Before Writing to Media’ option chosen when doing backup more often than DBCC CHECK DATABASE.

BACKUP DATABASE db
  TO DISK='fn'
  WITH
    RETAINDAYS=90,
    FORMAT,
    INIT,
    MEDIANAME='...',
    NAME='...',
    COMPRESSION;

WITH DIFFERENTIAL ...

BACKUP LOG db
  TO DISK='fn'
  WITH
    RETAINDAYS=90,
    NOINIT,
    MEDIANAME='...',
    NAME='...',
    COMPRESSION;

/* INIT overwrites existing backup file */
/* FORMAT overwrites media headers */

BACKUP DATABASE db
  FILEGROUP='fg' ...

Restoring a Database

RESTORE WITH VERIFY ONLY

Restore with restricted access:

WITH PARTIAL allows apply of additional backup even using RECOVERY. PIECEMEAL recovery. Tail log backup.

PITR:

RESTORE DATABASE db
  PAGE='n:m'
  FROM DISK=N'...'
  WITH
    FILE=1,
    NORECOVERY,
    STATS=5;
BACKUP LOG db;
RESTORE LOG db;

Piecemeal Restores

Use filegroup to backup and restore.