0% found this document useful (0 votes)
48 views51 pages

AutomatingSQLServerBackups Nowinski 04172019

The document provides an overview of SQL Server backup and recovery processes, including types of database files, recovery models, and backup strategies. It outlines the importance of transaction logs, different backup types (full, differential, transaction log, etc.), and offers recommendations for backup routines and automation using SSMS. Additionally, it includes steps for restoring databases and maintaining backup integrity.

Uploaded by

Mcp Chiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views51 pages

AutomatingSQLServerBackups Nowinski 04172019

The document provides an overview of SQL Server backup and recovery processes, including types of database files, recovery models, and backup strategies. It outlines the importance of transaction logs, different backup types (full, differential, transaction log, etc.), and offers recommendations for backup routines and automation using SSMS. Additionally, it includes steps for restoring databases and maintaining backup integrity.

Uploaded by

Mcp Chiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Server

Backup & Recovery


Basics
2019 Tribal Data Workshop
Transaction Log
Recovery Models
Backup Types
Recommendations
SSMS Demo
SQL Server Database Files

• Data File (MDF)


• Stores all the data
• Also stores database objects (tables, views, stored procedures, etc)

• Transaction Log File (LDF)


• Stores a record of modifications to the database
• Examples: INSERT, UPDATE, DELETE, ALTER, DROP commands
• Video: SQL Server Transactions
Transaction Log

Val1
MEMORY INSERT INTO Table (Col1, Col2, Col3)
Val2
VALUES (Val1, Val2, Val3)
Val3

DISK T1

Transaction Log (.LDF) Data File (.MDF)


Transaction Log

T1 T2 T3
Val1 Val1 Val1
MEMORY Checkpoint! Val2 Val2 Val2
Val3 Val3 Val3

Data Data Data


DISK T1 T2 T3 CP Data Data Data
Data Data Data

Transaction Log (.LDF) Data File (.MDF)


More Info: https://docs.microsoft.com/en-us/sql/relational-databases/logs/database-checkpoints-sql-server?view=sql-server-2017
Transaction Log
t

CP CP
T1 T2 T3 T4 T5 T7 T8 T9
1 2

Written To Disk Active Portion of Log


Not Written To Disk
Database Recovery Models
• Full Recovery Model
• All transactions logged and saved
• Allows Point-in-time recovery
• Recommended for production databases

• Simple Recovery Model


• Transactions are deleted after each checkpoint
• Point-in-time recovery not possible
• Recommended for development databases

• Bulk-Logged Recovery Model


• Certain types of transaction are not fully logged
Configuring Database Recovery Model

2. Select Options
3. Select Full

1. Right click database and select


Properties
SQL Server Backup Types
• Full Backup
• Differential Backup
• Transaction Log Backup
• Tail-log Backup
• Copy-Only
• Partial Backup
• File Backup
Full Backup

• The simplest type of backup

• A complete copy of the database

• File size can be large

• Restores database to a fixed point in time

• Prerequisite for differential or transaction log backups


Full Backup

9 pm error
Differential Backup

• Contains data that has changed since last full backup

• Based on the last full backup

• File size depends on the amount of data that has changed

• Restores database to a fixed point in time


Differential Backup

9 pm error
Transaction Log Backup

• Contains all log records since last full or t-log backup

• File size depends on transactions since last backup

• Incremental

• Restores to any point in time within the backup


Transaction Log Backup

13:29
Tail Log Backup

• Created during the recovery process before restoring a full backup

• SQL Server will prompt to back up the current transaction log

• The last backup to perform before starting the recovery process


Copy-Only Backup

• Just like a full backup

• A complete copy of the database

• BUT not a based for differential or transaction log backups

• Useful when copying a database from on server to another


Recommendations

• CRITFC Backup Routine


• Full backup weekly (Friday 10pm)
• Differential backup daily (10pm)
• Transaction log backup hourly (9am-6pm)

• Verify backups weekly (Monday)


• Confirm backup files were created
• Restore backup files in test environment
Recommendations

• Use SSMS to automate database backups


• Use the CHECKSUM and VERIFY options
• Keep differential and t-log backups 3 weeks (minimum)
• Keep full backups for longer (12-24 months)
• Document backup & recovery procedures
• Secure backup files (3-2-1 rule)
3-2-1 Backup Rule
• Keep 3 copies of each database backup

• Keep 2 copies on different devices

• Keep 1 copy offsite


Links
• https://sqlbak.com/academy/
• https://www.sqlbackuprestore.com/trxlogrestoresequence.htm
• https://www.mssqltips.com/sqlservertip/3076/how-to-read-the-sql-
server-database-transaction-log/
• https://www.sqlskills.com/help/accidental-dba/
SSMS Demo:
Database Backups
Manual Back Up
Right click database and select
Tasks>Back Up…
Manual Back Up Select backup type

Select this option to


create a backup that
will not be part of a
backup chain

Click Add to
enter a path for
the new backup
file
Manual Back Up
1. Click here 2. Navigate to
destination folder

3. Enter file
name with
extension
Manual Back Up
1. Select Media 2. Select both the Verify
Options tab backup when finished
AND Checksum options

3. Click OK to perform the


database back up
SSMS Demo:
Restoring Databases
Restoring Databases

1. Take tail-log backup to save the active portion of log

2. Restore full backup

3. Restore most recent differential backup (if available)

4. Restore all transaction log backups + tail-log backup

5. Use WITH RECOVERY option to bring database back online


Restoring Databases
Restoring Databases

Scroll right for


details

Backups available for


this database
Restoring Databases

Full backup Log


Sequence Number
(LSN) Differential and Transaction The LSN of the full backup
log backup full LSNs must upon which the Differential
match the Full backup First and Transaction Log
LSN backups are based
Restoring Databases

Click here to set a specific recovery


point in time. Otherwise, database will
restore to point in time displayed here
Restoring Databases Select specific date time radio button
and set Date and Time values. This
allows a database restore to a point in
time just before an error

Click OK to accept this values and


return to the main restore screen. This
will not run the restore process
Restoring Databases Select this option overwrite
existing MDF and LDF files
when database is restored
from backup

Options tab

Select this option to back up


the transaction log before
restoring the database from
Tail-log backup destination
backups
Restoring Databases
Restores the database from
backups and leaves database
in an active “online” state
ready for use

Leaves database in an
“restoring” state ready for
additional backup files to be
restored. Db is unavailable for use
until final backup is restored with
recovery
Restoring Databases

Click here to test


backup files

Backups available for


this database

Click OK to restore database


from backups
SSMS Demo:
Maintenance Plan
(Automated Back up)
Automating Backups
We recommend practicing these steps in development
environment before implementing on production server

Right click and select Create New


Maintenance Plan to begin
Automating Backups

Click the unpin icon to hide the


Object Explorer and enlarge the
Maintenance Plan workspace
Automating Backups

2. Enter an appropriate name (like


Full Backups) and then click here to
open the schedule window

1. Double click Subplan_1 to


open Subplan Properties
Window.
Automating Backups

1. Select days of week


this backup job will run

2. Set time of day


backup job will run

3. Click OK
Automating Backups

Drag and drop Back Up Database


Task from the Tool Bar into the
workspace
Automating Backups

1. Double click to open properties

2. Select Backup type

3. Select database(s) to backup


Automating Backups
1. Select Destination Tab

2. Set destination path

3. Enter backup file


extension
Automating Backups
1. Select Options Tab

2. Select Perform
Checksum and Verify
backup integrity options

3. Click OK
Automating Backups
2. Drag the green arrow from
Back Up task to Clean Up task
to set task execution order

1. Drag and drop Maintenance


Clean Up task from the Tool Bar
into the workspace
Automating Backups
1. Double click to open
2. Select folder to search
properties

3. Set file type

4. Set as needed. CRITFC


saves database backups
on the server for 21 days.
Old backup files are
automatically deleted.
Automating Backups

2. Click the X to close


maintenance plan tab
1. Save maintenance after saving
plan

Note: an asterisk indicates


unsaved changes. This will
disappear after saving.
Automating Backups
Or select Object Explorer
from the View Menu

Click this tab to expand


the Object Explorer
Automating Backups

Verify new maintenance


plan has been saved

Each subplan should appear


as a separate Job
Automating Backups
Test each job:

Right click and select Start Job at


Step to manually trigger

View History provides helpful


info when job execution fails

You might also like