Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Backup
Backup
Backs up data while being changed Dos not acquire locks and ignores existing locks
Backs up changes made to the database wile being backed up - Performs a checkpoint and records the LSN of the oldest active transaction - Backs up data pages directly as is - Backs up transactions since the LSN recorded (including open transactions)
Degrades performance by only 5% 10%
Syntax
BACKUP DATABASE {database_name | @database_name_var} TO <backup_device> [,...n] [WITH [BLOCKSIZE = {blocksize | @blocksize_variable}] [[,] DESCRIPTION = {text | @text_variable}] [[,] DIFFERENTIAL] [[,] EXPIREDATE = {date | @date_var} | RETAINDAYS = {days | @days_var}] [[,] FORMAT | NOFORMAT] [[,] {INIT | NOINIT}] [[,] MEDIADESCRIPTION = {text | @text_variable}] [[,] MEDIANAME = {media_name | @media_name_variable}] [[,] [NAME = {backup_set_name | @backup_set_name_var}] [[,] {NOSKIP | SKIP}] [[,] {NOUNLOAD | UNLOAD}] [[,] [RESTART] [[,] STATS [= percentage]] ]
Permissions
BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role, db_owner fixed database role, who can transfer permissions to other users, and to members of the db_backupoperator fixed database role.
Backup media
Disk file (including network location) - For a network location, make sure the service MSSQLServer loads with a domain user, and that that user has sufficient NTFS permissions Local tape device - Can mix SQL Server backups and NT backups Pipe (for self developed / 3rd party backup software)
Examples
USE master EXEC sp_addumpdevice 'disk','mydiskdump', 'c:\dump\dump1.bak
USE master EXEC sp_addumpdevice 'disk', '\\servername\sharename\path\filename.ext' USE master EXEC sp_addumpdevice 'tape', 'tapedump1', '\\.\tape0'
Media set
Create a media set by specifying more than one device in the backup statement. All devices must be of the same type (DISK | TAPE | PIPE) Cannot use a device that is part of a media set alone, unless you specify the FORMAT option. In this case, backups from the original media set can not be restored.
Full backup
Is required for following differential or transaction log backups Is current to the time the backup is finished
Examples: BACKUP DATABASE db1 TO DISK = \\servername\sharename\devname.bak BACKUP DATABASE db1 TO mydiskdump WITH INIT BACKUP DATABASE db1 TO mydiskdump WITH NOINIT
Differential backup
Requires a preceding full backup Backs up changed pages since the last full backup When restoring, the full backup and the last differential backup is needed If a row was modified several times, backs up the current image of the row Specify the option WITH DIFFERENTIAL in the BACKUP statement
Example
-- Create a full database backup first. BACKUP DATABASE MyNwind TO MyNwind_1 WITH INIT GO -- Time elapses. -- Create a differential database backup, appending the backup -- to the backup device containing the database backup. BACKUP DATABASE MyNwind TO MyNwind_1 WITH DIFFERENTIAL GO
Syntax
BACKUP LOG {database_name | @database_name_var} { [WITH { NO_LOG | TRUNCATE_ONLY }] } | { TO <backup_device> [,...n] [WITH [BLOCKSIZE = {blocksize | @blocksize_variable}] [[,] DESCRIPTION = {text | @text_variable}] [[,] EXPIREDATE = {date | @date_var} | RETAINDAYS = {days | @days_var}] [[,] FORMAT | NOFORMAT] [[,] {INIT | NOINIT}] [[,] MEDIADESCRIPTION = {text | @text_variable}] [[,] MEDIANAME = {media_name | @media_name_variable}] [[,] [NAME = {backup_set_name | @backup_set_name_var}] [[,] NO_TRUNCATE] [[,] {NOSKIP | SKIP}] [[,] {NOUNLOAD | UNLOAD}] [[,] [RESTART] [[,] STATS [= percentage]] ] }
Example
-- Create the log backup device. USE master EXEC sp_addumpdevice 'disk', 'MyNwindLog1', 'c:\mssql7\backup\MyNwindLog1.dat' -- Update activity has occurred before this point. -- Back up the log of the MyNwind database. BACKUP LOG MyNwind TO MyNwindLog1
Acknowledgements:
Most of the info for the following topics were taken from the book Inside SQL Server 7.0 by Kalen Delaney
Syntax
BACKUP DATABASE {database_name | @database_name_var} <file = logical_file_name | filegroup = filegroup_name > [,...n] TO <backup_device> [,...n] [WITH
Examples
-- Back up the MyNwind file(s) and filegroup(s) BACKUP DATABASE MyNwind FILE = 'MyNwind_data_1', FILEGROUP = 'new_customers', FILE = 'MyNwind_data_2', FILEGROUP = 'first_qtr_sales' TO MyNwind_1 GO
msdb model
Detach a database from the server and, optionally, run UPDATE STATISTICS on all tables before detaching (use the false option if you are moving / copying the database to a read only media). Copy | move the files to the target location Run sp_attach_db or sp_attach_single_file_db on the target server
Backup Options
Backup Options
NAME backup name DESCRIPTION backup description INIT, NOINIT overwrite | append (if NOSKIP is specified, performs safety checks) SKIP, NOSKIP whether to perform a safety check FORMAT | NOFORMAT whether to rewrite the backup device and ignore existing backup sets and not perform any safety checks MEDIADESCRIPTION MEDIANAME if supplied, performs a media set name check
Backup Options
EXPIREDATE | RETAINDAYS checked if NOSKIP is performed RESTART restarts the backup operation at the point it was interrupted This option can only be used for backups directed to tape media and for backups that span multiple tape volumes. A restart operation never occurs on the first volume of the backup. NOUNLOAD | UNLOAD STATS = n - Informs the percentage of the backup operation every n percent of the backup BLOCKSIZE for media that requires a special block size