+ All Categories
Home > Documents > Backup & Restore Part I

Backup & Restore Part I

Date post: 04-Jun-2018
Category:
Upload: divandann
View: 236 times
Download: 0 times
Share this document with a friend

of 43

Transcript
  • 8/13/2019 Backup & Restore Part I

    1/43

    Backup & Restore

    Part I

    Backup

  • 8/13/2019 Backup & Restore Part I

    2/43

    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 activetransaction

    - Backs up data pages directly as is

    - Backs up transactions since the LSN recorded (including opentransactions)

    Degrades performance by only 5%10%

  • 8/13/2019 Backup & Restore Part I

    3/43

    Syntax

    BACKUP DATABASE {database_name| @database_name_var}TO [,...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]]

    ]

  • 8/13/2019 Backup & Restore Part I

    4/43

    Permissions

    BACKUP DATABASE and BACKUP LOG

    permissions default to members of the

    sysadminfixed server role, db_owner

    fixed database role, who can transfer

    permissions to other users, and to members

    of the db_backupoperatorfixed databaserole.

  • 8/13/2019 Backup & Restore Part I

    5/43

    Backup media

    Disk file (including network location)

    - For a network location, make sure the serviceMSSQLServer loads with a domain user, and that that userhas sufficient NTFS permissions

    Local tape device

    - Can mix SQL Server backups and NT backups

    Pipe (for self developed / 3rdparty backup software)

  • 8/13/2019 Backup & Restore Part I

    6/43

    Named dump devices

    Named dump devices

    - Logical name maps to a disk or a tape device

    - If physical location changes, need to drop and recreate the device, but

    all automated jobs do not need to be changed

    sp_addumpdevice[@devtype =]

    disk | pipe | tape,[@logicalname =]'logical_name',

    [@physicalname =] 'physical_name'

    Permissions:

    Execute permissions default to members of the diskadminfixed serverrole.

  • 8/13/2019 Backup & Restore Part I

    7/43

    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

  • 8/13/2019 Backup & Restore Part I

    8/43

    From Enterprise Manager

  • 8/13/2019 Backup & Restore Part I

    9/43

    Supplying the direct location of

    the backup device

    - Has the same abilities as the named dump

    device

    - If the physical location of the device

    changes, need to change it in all automated

    jobs.

  • 8/13/2019 Backup & Restore Part I

    10/43

    Media set

    Create a media set by specifying more thanone 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 FORMAToption. In this case, backups from theoriginal media set can not be restored.

  • 8/13/2019 Backup & Restore Part I

    11/43

    Fu l l backup

    Is required for following differential or transactionlog backups

    Is current to the time the backup is finished

    Examples:

    BACKUP DATABASE db1 TO DISK =

    \\servername\sharename\devname.bak

    BACKUP DATABASE db1 TOmydiskdump WITH INIT

    BACKUP DATABASE db1 TOmydiskdump WITH NOINIT

  • 8/13/2019 Backup & Restore Part I

    12/43

    From Enterprise Manager

  • 8/13/2019 Backup & Restore Part I

    13/43

    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

  • 8/13/2019 Backup & Restore Part I

    14/43

    Example

    -- Create a full database backup first.

    BACKUP DATABASE MyNwind

    TO MyNwind_1

    WITH INITGO

    -- Time elapses.

    -- Create a differential database backup,appending the backup

    -- to the backup device containing the databasebackup.

    BACKUP DATABASE MyNwind

    TO MyNwind_1

    WITH DIFFERENTIAL

    GO

  • 8/13/2019 Backup & Restore Part I

    15/43

    From Enterprise Manager

  • 8/13/2019 Backup & Restore Part I

    16/43

    Transaction log backup

    Requires a preceding full backup (and

    optionally a differential backup)

    Backs up committed and uncommitted

    transactions from the Transaction Log

    Truncates the inactive part of the

    transaction log* (until the oldest open

    transaction)

  • 8/13/2019 Backup & Restore Part I

    17/43

    Syntax

    BACKUP LOG {database_name| @database_name_var} {

    [WITH{ NO_LOG | TRUNCATE_ONLY }]

    }|{

    TO [,...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]] ] }

  • 8/13/2019 Backup & Restore Part I

    18/43

    Example

    -- Create the log backup device.

    USE master

    EXEC sp_addumpdevice 'disk', 'MyNwindLog1',

    'c:\mssql7\backup\MyNwindLog1.dat'

    -- Update activity has occurred before thispoint.

    -- Back up the log of the MyNwind database.BACKUP LOG MyNwind

    TO MyNwindLog1

  • 8/13/2019 Backup & Restore Part I

    19/43

    From Enterprise Manager

  • 8/13/2019 Backup & Restore Part I

    20/43

    Acknowledgements:

    Most of the info for the following topics were taken from the

    book Inside SQL Server 7.0by Kalen Delaney

  • 8/13/2019 Backup & Restore Part I

    21/43

    Log truncate mode

    When a database is in log truncate mode it is automatically

    truncated when a checkpoint occurs.

    In log truncate mode a checkpoint occurs in the followingcircumstances:

    The log becomes 70 percent full.

    The number of log records reaches the number SQL Server

    estimates it can process during the time specified in the recovery

    intervaloption.

  • 8/13/2019 Backup & Restore Part I

    22/43

    Log truncate mode

    A database will be in log truncate mode in the following

    situations:

    - The database option trunc. log on chkpt. Is set to true- The database was never fully backed up

    - A non logged operation was performed against the

    database and it was never fully backed up since

    - The Transaction Log was manually truncated using theBACKUP LOG WITH NO_LOG | TRUNCATE_ONLY

    (in SQL Server 7.0 these are synonyms)

  • 8/13/2019 Backup & Restore Part I

    23/43

    Shrinking the transaction log

    The Transaction Log is built internally from Virtual log files.

    Transactions are written serially to the Transaction Log File.

    The active portion of the transaction log begins from the oldestopen transaction until the last transaction.

    Virtual log files are marked as reusable if they contain inactive

    log records and were backed up.

    The Transaction Log File can be truncated: Only in full virtual log files.

    Only from the end.

    Only if they are inactive and are marked as reusable.

  • 8/13/2019 Backup & Restore Part I

    24/43

    Shrinking the transaction log

    This may lead to situations where the Transaction Log can not be truncated. Toovercome this, use the following procedure:

    1. Backup or truncate the log to make sure earlier Virtual Log Files are reusable2. Execute dummy transactions (in a loop) so that the active VLF will move to an

    earlier location.

    3. Execute DBCC SHRINKDATABASE or DBCC SHRINKFILE to mark ashrinkpoint.

    4. Repeat step 1 again to force the physical shrinkage.

    * Tip: Use the DBCC LOGINFO(dbname) to see a list of the virtual log files.Those with status 2 are active. Continue with the dummy transactions until theactive VLF is at the beginning.

  • 8/13/2019 Backup & Restore Part I

    25/43

    BACKUP LOG WITH NO_TRUNCATE

    This option was provided to enable backing up the Transaction Log in case the

    disk containing the data files is damaged but the Transaction Log is still

    intact.

    Currently this option is available only if the .mdf file is still available.

    To prepare for such a senario:

    1. Place the PRIMARY FILEGROUP and the Transaction Log on the same

    physical disk.

    2. Create an additional filegroup:

    ALTER DATABASE databaseADD FILEGROUPfilegroup_name

    3. Mark the new filegroup as default:

    ALTER DATABASE databaseMODIFY FILEGROUPfilegroup_nameDEFAULT

  • 8/13/2019 Backup & Restore Part I

    26/43

    Files and File Groups backup

    Use with Very Large Databases were the backup

    window is not sufficient for a full backup

    If an index is created on a filegroup, all thefilegreoup or all the files belonging to that

    filegroup are need to be backed up as a unit

    If a table was created on one filegroup and its

    indexes were created on separate filegroups, all

    the filegroups involved need to be backed up as a

    unit.

  • 8/13/2019 Backup & Restore Part I

    27/43

    Syntax

    BACKUP DATABASE {database_name|

    @database_name_var}

    [,...n]

    TO [,...n]

    [WITH

  • 8/13/2019 Backup & Restore Part I

    28/43

    Examples

    -- Back up the MyNwind file(s) and

    filegroup(s)

    BACKUP DATABASE MyNwindFILE = 'MyNwind_data_1',

    FILEGROUP = 'new_customers',

    FILE = 'MyNwind_data_2',

    FILEGROUP = 'first_qtr_sales'

    TO MyNwind_1

    GO

  • 8/13/2019 Backup & Restore Part I

    29/43

    From Enterprise Manager

  • 8/13/2019 Backup & Restore Part I

    30/43

  • 8/13/2019 Backup & Restore Part I

    31/43

    sp_detach_db & copy

    sp_detach_db[@dbname=] 'dbname'[,[@skipchecks=] 'skipchecks']

    Detach a database from the server and, optionally,run UPDATE STATISTICS on all tables beforedetaching (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 onthe target server

  • 8/13/2019 Backup & Restore Part I

    32/43

    Backup Options

  • 8/13/2019 Backup & Restore Part I

    33/43

    Backup Options

    NAMEbackup name

    DESCRIPTIONbackup description

    INIT, NOINIToverwrite | append (if NOSKIP is specified, performs

    safety checks)

    SKIP, NOSKIPwhether to perform a safety check

    FORMAT | NOFORMATwhether to rewrite the backup device and

    ignore existing backup sets and not perform any safety checks

    MEDIADESCRIPTION

    MEDIANAMEif supplied, performs a media set name check

  • 8/13/2019 Backup & Restore Part I

    34/43

    Backup Options

    EXPIREDATE | RETAINDAYSchecked if NOSKIP is performed

    RESTARTrestarts the backup operation at the point it was

    interrupted

    This option can only be used for backups directed to tape media andfor 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

    BLOCKSIZEfor media that requires a special block size

  • 8/13/2019 Backup & Restore Part I

    35/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    36/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    37/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    38/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    39/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    40/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    41/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    42/43

    Database Maintenance Plans

  • 8/13/2019 Backup & Restore Part I

    43/43

    Database Maintenance Plans


Recommended