SlideShare a Scribd company logo
Antonios Chatzipavlis
DATA SOLUTIONS CONSULTANT & TRAINER
SQL Server Backup/Restore Revealed
SQL Night #43
Sep 26, 2020
20:30
SQL Nights
SQL server Backup Restore Revealed
Please mute
your mic
1988 2000 Founderv 6.0 60 +2010
Antonios Chatzipavlis
Data Solutions Consultant & Trainer
V.102010 - 2020
A community for Greek professionals who use the
Microsoft Data Platform
Connect / Explore / Learn
WebminarsArticles
Videos News
EventsResources
@sqlschool@antoniosch
Sqlschoolgr
Page
Sqlschool
User Group
Sqlschool.gr
Group
SQLschoolGR
channel
SQL server Backup Restore Revealed
Take Your Career to New Heights
Save $50 USD
Register for PASS Summit 2020 and as a participant in SQLschool.gr,
you can save $50 USD the registration price.
To claim use code* LGDISET1I.
* Unique discount code cannot be applied retroactively and cannot be combined with any other offers.
Presentation Content
SQL Server
Backup/Restore
Revealed
• Database Architecture Basics
• Backup / Restore
• Backup / Restore Internals
Database Architecture
Basics
Connect / Explore / Learn
Database Architecture
Data file(s)
8KB Pages
VLFs
T-log file
Database
Connect / Explore / Learn
Buffer Cache usage
Data file(s)
8KB Pages
VLFs
T-log file
Database
Buffer cache
Memory
Connect / Explore / Learn
Transaction log usage
Data file(s)
8KB Pages
VLFs
T-log file
Database
Buffer cache
Memory
Commit
returned
Pages marked as dirty
Connect / Explore / Learn
Checkpoint
Data file(s)
8KB Pages
VLFs
T-log file
Database
Buffer cache
Memory
Pages marked as dirty
checkpoint
Connect / Explore / Learn
Checkpoint frequency
Data file(s)
8KB Pages
VLFs
T-log file
Database
Buffer cache
Memory
DD D D D D
Connect / Explore / Learn
Automatic
Indirect
Manual
Internal
CHECKPOINT statement configures the target recovery duration
Checkpoint Options
Backup / Restore
Connect / Explore / Learn
Backup / Restore Strategy
Understanding RPO and RTO
(t)
DISASTER
RPO RTO
backup Restore end
Lost data DB Down
t1 t2 t3
Connect / Explore / Learn
Retention & Testing Policy Backup Integrity
•Insufficient Copies of Backups
•Insufficient Data on the Backups
•Unreadable Backups
•Unavailable Hardware
•Old Hardware
•Misaligned Hardware
•Mirrored Backups
•Backup Verification
•Backup storage size
•Backup security
Managing Backups
Connect / Explore / Learn
Backup Device(s)
Backup Device
Slot 1 – Backup A
Slot 2 – Backup B
Slot 3 – Backup C
Slot 4 – Backup D
Slot 5 – Backup E
Slot N – Backup …
Backup devices types
• Physical
• Logical
• Azure Blob storage
Connect / Explore / Learn
Media Set
Media Family
Backup Sets, Media Sets, Media Families
Backup Device A
Slot 1 – Backup Database A
Slot 2 – Backup Database B
Slot 3 – Backup Database C
Backup Set
Backup Set
Backup Set
Media Header
Connect / Explore / Learn
Media Set
Media Family 2/2Media Family 1/2
Backup Sets, Media Sets, Media Families
Backup Device A
Slot 1 – Backup Database A (50%)
Slot 2 – Backup Database B (50%)
Slot 3 – Backup Database C (50%)
Media Header
Backup Device B
Slot 1 – Backup Database A (50%)
Slot 2 – Backup Database B (50%)
Slot 3 – Backup Database C (50%)
Backup Set
Backup Set
Backup Set
Media Header
Connect / Explore / Learn
Recovery Models
Simple
No T-log backups
Auto truncate T-log
Full
T-log backups required
Avoids data loss due to a
damaged or missing data
file
Recovery at specific point
in time
Bulk logged
T-log backups required
Enhance the performance
of bulk copy operation
Reduce log space by using
minimal logging for many
bulk operations
Connect / Explore / Learn
Backup Types
Full Differential Transaction Log Tail Log
Copy Only Partial Filegroup Snapshot
Connect / Explore / Learn
BACKUP TYPES SIMPLE FULL BULK LOGGED
Full ● ● ●
Differential ● ● ●
Transaction Log ● ●
Tail Log ●
Copy Only ● ● ●
Partial ● ● ●
Filegroup ● ● ●
Snapshot ●
Backup Types / Recovery Model
Connect / Explore / Learn
Full Backup
(t)
New
DB FULL FULL FULL
Connect / Explore / Learn
Restore Full Backup
(t)
New
DB FULL FULL FULL
t4
DAMAGE
RESTORE
Connect / Explore / Learn
Differential Backup
(t)
New
DB FULL DIFF DIFF DIFF
Connect / Explore / Learn
Restore Differential Backup
(t)
New
DB FULL DIFF DIFF DIFF
t5
DAMAGE
RESTORE RESTORE
Connect / Explore / Learn
Transaction Log Backup
(t)
New
DB FULL LOG LOG DIFF LOG LOG
Connect / Explore / Learn
Restore Transaction Log Backup
(t)
New
DB FULL LOG LOG DIFF LOG LOG
t7
DAMAGE
RESTORE RESTORE RESTORE RESTORE
Connect / Explore / Learn
Tail Log Backup
(t)
New
DB FULL LOG LOG DIFF LOG LOG DAMAGE
TAIL
LOG
RPO
A tail-log backup captures any log records which has not
yet been backed up by the last transactional log backup.
Connect / Explore / Learn
Copy Only Backup
(t)
New
DB FULL LOG LOG DIFF LOG LOG
t2-3
FULL
COPY ONLY
Connect / Explore / Learn
Partial Backup
(t)
New
DB FULL
Primary
filegroup
Read only
Filegroup
Read/Write
Filegroup
FULL
READ/WRITE
PARTIAL
FULL
READ ONLY
PARTIAL
DIFFERENTIAL
READ/WRITE
PARTIAL
DIFFERENTIAL
READ/WRITE
PARTIAL
All SQL Server recovery
models support partial
backups
Partial backups are designed for
use under the
simple recovery model
to improve flexibility for backing
up very large databases that
contain one or more read-only
filegroups.
Connect / Explore / Learn
Restore Partial Backup
(t)
New
DB FULL
Primary
filegroup
Read only
Filegroup
Read/Write
Filegroup
FULL
READ/WRITE
PARTIAL
FULL
READ ONLY
PARTIAL
DIFFERENTIAL
READ/WRITE
PARTIAL
DIFFERENTIAL
READ/WRITE
PARTIAL
t6
DAMAGE
RESTORE RESTORERESTORE
Connect / Explore / Learn
Filegroup Backup
(t)
New
DB FULL
Primary
filegroup
Other
Filegroups
FILEGROUP
A
FILEGROUP
B
FILEGROUP
C
FILEGROUP
A
FILEGROUP
B
FILEGROUP
C
t0A
LOG
t1A
LOG
t1B
LOG
t2A
LOG
t2B
LOG
t3A
LOG
t3B
LOG
t4A
LOG
t4B
LOG
t5A
LOG
t5B
LOG
t6A
LOG
t6B
LOG
t7A
LOG
t7B
LOG
Connect / Explore / Learn
Restore Filegroup Backup
(t)
New
DB FULL
Primary
filegroup
Other
Filegroups
FILEGROUP
A
FILEGROUP
B
FILEGROUP
C
FILEGROUP
A
FILEGROUP
B
FILEGROUP
C
t0A
LOG
t1A
LOG
t1B
LOG
t2A
LOG
t2B
LOG
t3A
LOG
t3B
LOG
t4A
LOG
t4B
LOG
t5A
LOG
t5B
LOG
t6A
LOG
t6B
LOG
t7A
LOG
t7B
LOG
t8
DAMAGE
FILEGROUP B
t8’
TAIL LOG
Connect / Explore / Learn
8KB Pages
Database Snapshot
Data file(s)
Database
Snapshot
SELECT on
Snapshot
We can restore this snapshot, but it should not be considered as a backup
Connect / Explore / Learn
File-snapshot backup
SQL Server instance on Azure Virtual Machine ( SQL Server 2016 + )
SQL Server Instance
On Azure VM
DB
Azure Blob Storage
(t)
FULL LOG LOG LOG LOG LOG LOG LOG
t9
DAMAGETAIL LOG
RESTORE ALL (SEQUENCIAL)
Azure Blob Storage
TO URL https://<storagename>.blob.core.windows.net/<container>/xxx.bak
FILE_SNAPSHOT
RESTORE
Connect / Explore / Learn
When already running FULL DIFFERENTIAL LOG
Full Backup Blocked Blocked
Allowed
( >SQL 2005)
Differential Backup Blocked Blocked
Allowed
( >SQL 2005)
Log Backup
Allowed
( >SQL 2005)
Allowed
( >SQL 2005)
Blocked
Backup Concurrency in the same database
Connect / Explore / Learn
Data Copy
Creates files and copies data to the files
Redo Phase
Applies committed transactions from restored log entries
Undo Phase
Rolls back transactions that were uncommitted at the recovery point
Phases of the Restore Process
Connect / Explore / Learn
RESTORE LABELONLY
Returns information about the backup media on a specified backup device.
RESTORE HEADERONLY
Returns all the backup header information for all backup sets on a particular backup device.
RESTORE FILELISTONLY
Returns a list of data and log files contained in a backup set.
RESTORE VERIFYONLY
Verifies the backup but does not restore it and checks to see that the backup set is complete, and the entire
backup is readable.
Retrieving Backup Metadata
Backup / Restore
Special
Restore Cases
Page(s) Restore
Online Restore – Enterprise Edition
(t)
DB
Full Recovery
Model
FULL
LOG LOG DIFF LOG LOG
t7
Page corruption
823, 824
PAGE(s)
RESTORE RESTORE RESTORE RESTORE
TAIL LOG
RESTORE
msdb dbo suspect_pages;
Page(s) Restore
Offline Restore – Enterprise and Standard Editions
(t)
DB
Full Recovery
Model
FULL
LOG LOG DIFF LOG LOG
t7
Page corruption
823, 824
PAGE(s)
RESTORE RESTORE RESTORE RESTORE
TAIL LOG
RESTORE
msdb dbo suspect_pages;
Page Restore
Restore to a point in time
(t)
DB
Full Recovery
Model
FULL
LOG LOG DIFF LOG LOG
t6’
Some crucial
data deleted
LOG
RESTORE RESTORE RESTORE RESTORE RESTORE
t7’
Discover
RESTORE LOG ‘<dbname>’
FROM backupdevice
WITH STOPAT = ‘YYYY/MM/DD HH:MM:SS’
STOPAT = { 'datetime'| @datetime_var }
STOPATMARK = { 'mark_name' | 'lsn:lsn_number’ }
STOPBEFOREMARK = { 'mark_name' | 'lsn:lsn_number' } [ AFTER 'datetime']
DATA
LOSS
Connect / Explore / Learn
master
• Start the server instance in single-user mode by
using the –m startup option.
• Use a RESTORE DATABASE statement to restore a
full database backup of the master database by
using the sqlcmd utility.
• Terminate your sqlcmd connection.
• Remove the single-user startup parameter.
• Restart SQL Server.
model
• Start the server instance with TF3608.
• Use a RESTORE DATABASE statement to restore a
full database backup of the master database by
using the sqlcmd utility.
• Terminate your sqlcmd connection.
• Remove the single-user startup parameter.
• Restart SQL Server.
msdb
• You can restore it by using the RESTORE
DATABASE statement as you would a user db
Restore System databases
Connect / Explore / Learn
Transaction Log Truncation
T-logfile
Start End End
File growth
Connect / Explore / Learn
Transaction Log Truncation
T-logfile
Start
End
Start
End
Truncation of T-Log
Smart Backups
Connect / Explore / Learn
Differential Backup
Commonly used case
Restore chain too long impacting
RTO
Connect / Explore / Learn
Smart differential backup
New approach ( SQL Server 2016 + )
modified_extent_page_count -> sys.dm_db_file_space_usage
Total number of pages modified in allocated extents of the file since last full database backup. The modified page count
can be used to track differential changes in the database since last full backup to decide if differential backup is beneficial
SELECT file_id,
total_page_count,
modified_extent_page_count,
cast (( modified_extent_page_count * 1.0 /
total_page_count * 1.0 )
* 100.0 as decimal(5,2)) as pctchanges
FROM sys.dm_db_file_space_usage
Connect / Explore / Learn
Transaction Log Backup
Commonly used case
Not Adaptive
• Frequent Auto grows
• VLF Fragmentation
• Inconsistent backup size
Connect / Explore / Learn
Smart transaction log backup
New approach ( SQL Server 2016 + )
select from sys.dm_db_log_stats DB_ID
Adaptive
• Minimal Auto grows
• No VLF Fragmentation
• Consistent backup size
Smart Backups
Backup Internals
Connect / Explore / Learn
Memory out of buffer cache
How SQL Server Backup Works
DB
1 Backup command executed
2 Checkpoints (few times)
Checkpoints
3 Workers creation
Controller
Read thread
(one per volume)
Write thread
(one per backup device)
4 Start buffering data (async I/O)
backup
device
BUFFER
BUFFER
BUFFER
BUFFER
BUFFER
BUFFER
BUFFER
BUFFER
5 Writing buffered data
6 Exchange the buffers
Connect / Explore / Learn
BufferCount
• Specifies the total number of I/O buffers to be used
for the backup operation.
• You can specify any positive integer
• Large numbers of buffers might cause “out of
memory” errors because of inadequate virtual
address space in the Sqlservr.exe process.
MaxTransferSize
• Specifies the largest unit of transfer in bytes to be
used between SQL Server and the backup media.
• The possible values are multiples of 65536 bytes (64
KB) ranging up to 4194304 bytes (4 MB).
Important Backup Options
Calculate the Buffer Count Formula
Backup Internals
Connect / Explore / Learn
Backup related wait types
BACKUPBUFFER
Occurs when a backup
task is waiting for data
or is waiting for a
buffer in which to store
data.
BACKUPIO
Occurs when a backup
task is waiting for data
or is waiting for a
buffer in which to store
data.
BACKUPTHREAD
Occurs when a task is
waiting for a backup
task to finish.
Backup Wait Stats
Connect / Explore / Learn
SQL Server tracks all backup activity
in the following tables in the msdb
database:
• msdb.dbo.backupfile
• msdb.dbo.backupfilegroup
• msdb.dbo.backupmediafamily
• msdb.dbo.backupmediaset
• msdb.dbo.backupset
Viewing Backup History
https://bit.ly/365LosB
Connect / Explore / Learn
Deleting Backup History
sp_delete_backuphistory @oldest_date
sp_delete_database_backuphistory @database_name
Connect / Explore / Learn
Backup/Restore operation execution info
How to know the execution percentage and completion time for a backup / restore operation
SELECT SUBSTRING
case
when then
else
end
DATEADD
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text
INNER JOIN sys.dm_exec_sessions
INNER JOIN sys.dm_exec_connections
WHERE
https://www.sqlschool.gr/blog/how-to-know-the-execution-percentage-and-completion-time-for-a-task-1054.aspx
Any
questions
Thank you!
@antoniosch - @sqlschool
./sqlschoolgr - ./groups/sqlschool
./c/SqlschoolGr
SQLschool.gr Group
Antonios Chatzipavlis
Data Solutions Consultant & Trainer
A community for Greek professionals who use the Microsoft Data Platform
Copyright © 2010-2020 SQLschool.gr. All right reserved. PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION
SQL server Backup Restore Revealed

More Related Content

PPTX
Data Guard Architecture & Setup
PPTX
SQL Server High Availability and Disaster Recovery
PPT
PDF
Nabil Nawaz Oracle Oracle 12c Data Guard Deep Dive Presentation
PDF
Oracle data guard for beginners
PPTX
Oracle DBA
PPT
Oracle data pump
PPT
Oracle archi ppt
Data Guard Architecture & Setup
SQL Server High Availability and Disaster Recovery
Nabil Nawaz Oracle Oracle 12c Data Guard Deep Dive Presentation
Oracle data guard for beginners
Oracle DBA
Oracle data pump
Oracle archi ppt

What's hot (20)

PPT
Oracle Data Guard
PPT
Backup And Recovery
PDF
The Oracle RAC Family of Solutions - Presentation
PDF
Enterprise manager 13c
PDF
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
PDF
Advanced RAC troubleshooting: Network
PDF
InnoDB Flushing and Checkpoints
PDF
Oracle Enterprise Manager Cloud Control 13c for DBAs
PDF
Migration to Oracle Multitenant
PPT
Oracle backup and recovery
PDF
All Oracle-dba-interview-questions
PDF
New Generation Oracle RAC Performance
PDF
監査ログをもっと身近に!〜統合監査のすすめ〜
PDF
Average Active Sessions RMOUG2007
PPTX
Oracle ASM Training
PDF
MySQL Security
PPTX
Backing Up and Recovery
PDF
Exadata master series_asm_2020
PPTX
Why oracle data guard new features in oracle 18c, 19c
PDF
Oracle Performance Tuning Fundamentals
Oracle Data Guard
Backup And Recovery
The Oracle RAC Family of Solutions - Presentation
Enterprise manager 13c
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Advanced RAC troubleshooting: Network
InnoDB Flushing and Checkpoints
Oracle Enterprise Manager Cloud Control 13c for DBAs
Migration to Oracle Multitenant
Oracle backup and recovery
All Oracle-dba-interview-questions
New Generation Oracle RAC Performance
監査ログをもっと身近に!〜統合監査のすすめ〜
Average Active Sessions RMOUG2007
Oracle ASM Training
MySQL Security
Backing Up and Recovery
Exadata master series_asm_2020
Why oracle data guard new features in oracle 18c, 19c
Oracle Performance Tuning Fundamentals
Ad

Similar to SQL server Backup Restore Revealed (20)

PPTX
Sql server lesson10
PPTX
Backup beyond just a strategy with SQL Server
PPTX
Prevent Recovery Amnesia - Forget The Backups
PPTX
Backup and restore
PPSX
MS SQL Backups explained by a DBA
PPTX
Backup And Recovery Planning
PPTX
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
PPT
Backup and Recovery Implementation
PPTX
SQLBits 2008 - SQL Server High Availability and Disaster Recovery Overview - ...
PDF
SQL Server Backup and Restore
PPTX
SQL Server 2014 Backup to Azure - SQL Saturday CR 2015
PPTX
Backup and recovery in sql server database
PDF
Restore Backup SQL Data
PPTX
my final ppresenntation.pptx
PPTX
Sql server lesson4_v2
PPTX
Sql server lesson4
PDF
Backup and Restore SQL Server Databases in Microsoft Azure
PDF
DB2 LUW - Backup and Recovery
PDF
Db2 recovery IDUG EMEA 2013
Sql server lesson10
Backup beyond just a strategy with SQL Server
Prevent Recovery Amnesia - Forget The Backups
Backup and restore
MS SQL Backups explained by a DBA
Backup And Recovery Planning
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
Backup and Recovery Implementation
SQLBits 2008 - SQL Server High Availability and Disaster Recovery Overview - ...
SQL Server Backup and Restore
SQL Server 2014 Backup to Azure - SQL Saturday CR 2015
Backup and recovery in sql server database
Restore Backup SQL Data
my final ppresenntation.pptx
Sql server lesson4_v2
Sql server lesson4
Backup and Restore SQL Server Databases in Microsoft Azure
DB2 LUW - Backup and Recovery
Db2 recovery IDUG EMEA 2013
Ad

More from Antonios Chatzipavlis (20)

PPTX
Data virtualization using polybase
PDF
Migrate SQL Workloads to Azure
PDF
Machine Learning in SQL Server 2019
PDF
Workload Management in SQL Server 2019
PDF
Loading Data into Azure SQL DW (Synapse Analytics)
PDF
Introduction to DAX Language
PDF
Building diagnostic queries using DMVs and DMFs
PDF
Exploring T-SQL Anti-Patterns
PDF
Designing a modern data warehouse in azure
PDF
Modernizing your database with SQL Server 2019
PDF
Designing a modern data warehouse in azure
PDF
SQLServer Database Structures
PDF
Sqlschool 2017 recap - 2018 plans
PDF
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
PDF
Microsoft SQL Family and GDPR
PDF
Statistics and Indexes Internals
PDF
Introduction to Azure Data Lake
PDF
Azure SQL Data Warehouse
PDF
Introduction to azure document db
PDF
Introduction to Machine Learning on Azure
Data virtualization using polybase
Migrate SQL Workloads to Azure
Machine Learning in SQL Server 2019
Workload Management in SQL Server 2019
Loading Data into Azure SQL DW (Synapse Analytics)
Introduction to DAX Language
Building diagnostic queries using DMVs and DMFs
Exploring T-SQL Anti-Patterns
Designing a modern data warehouse in azure
Modernizing your database with SQL Server 2019
Designing a modern data warehouse in azure
SQLServer Database Structures
Sqlschool 2017 recap - 2018 plans
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Microsoft SQL Family and GDPR
Statistics and Indexes Internals
Introduction to Azure Data Lake
Azure SQL Data Warehouse
Introduction to azure document db
Introduction to Machine Learning on Azure

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)

SQL server Backup Restore Revealed

  • 1. Antonios Chatzipavlis DATA SOLUTIONS CONSULTANT & TRAINER SQL Server Backup/Restore Revealed SQL Night #43 Sep 26, 2020 20:30 SQL Nights
  • 4. 1988 2000 Founderv 6.0 60 +2010 Antonios Chatzipavlis Data Solutions Consultant & Trainer
  • 5. V.102010 - 2020 A community for Greek professionals who use the Microsoft Data Platform Connect / Explore / Learn WebminarsArticles Videos News EventsResources @sqlschool@antoniosch Sqlschoolgr Page Sqlschool User Group Sqlschool.gr Group SQLschoolGR channel
  • 7. Take Your Career to New Heights Save $50 USD Register for PASS Summit 2020 and as a participant in SQLschool.gr, you can save $50 USD the registration price. To claim use code* LGDISET1I. * Unique discount code cannot be applied retroactively and cannot be combined with any other offers.
  • 8. Presentation Content SQL Server Backup/Restore Revealed • Database Architecture Basics • Backup / Restore • Backup / Restore Internals
  • 10. Connect / Explore / Learn Database Architecture Data file(s) 8KB Pages VLFs T-log file Database
  • 11. Connect / Explore / Learn Buffer Cache usage Data file(s) 8KB Pages VLFs T-log file Database Buffer cache Memory
  • 12. Connect / Explore / Learn Transaction log usage Data file(s) 8KB Pages VLFs T-log file Database Buffer cache Memory Commit returned Pages marked as dirty
  • 13. Connect / Explore / Learn Checkpoint Data file(s) 8KB Pages VLFs T-log file Database Buffer cache Memory Pages marked as dirty checkpoint
  • 14. Connect / Explore / Learn Checkpoint frequency Data file(s) 8KB Pages VLFs T-log file Database Buffer cache Memory DD D D D D
  • 15. Connect / Explore / Learn Automatic Indirect Manual Internal CHECKPOINT statement configures the target recovery duration Checkpoint Options
  • 17. Connect / Explore / Learn Backup / Restore Strategy Understanding RPO and RTO (t) DISASTER RPO RTO backup Restore end Lost data DB Down t1 t2 t3
  • 18. Connect / Explore / Learn Retention & Testing Policy Backup Integrity •Insufficient Copies of Backups •Insufficient Data on the Backups •Unreadable Backups •Unavailable Hardware •Old Hardware •Misaligned Hardware •Mirrored Backups •Backup Verification •Backup storage size •Backup security Managing Backups
  • 19. Connect / Explore / Learn Backup Device(s) Backup Device Slot 1 – Backup A Slot 2 – Backup B Slot 3 – Backup C Slot 4 – Backup D Slot 5 – Backup E Slot N – Backup … Backup devices types • Physical • Logical • Azure Blob storage
  • 20. Connect / Explore / Learn Media Set Media Family Backup Sets, Media Sets, Media Families Backup Device A Slot 1 – Backup Database A Slot 2 – Backup Database B Slot 3 – Backup Database C Backup Set Backup Set Backup Set Media Header
  • 21. Connect / Explore / Learn Media Set Media Family 2/2Media Family 1/2 Backup Sets, Media Sets, Media Families Backup Device A Slot 1 – Backup Database A (50%) Slot 2 – Backup Database B (50%) Slot 3 – Backup Database C (50%) Media Header Backup Device B Slot 1 – Backup Database A (50%) Slot 2 – Backup Database B (50%) Slot 3 – Backup Database C (50%) Backup Set Backup Set Backup Set Media Header
  • 22. Connect / Explore / Learn Recovery Models Simple No T-log backups Auto truncate T-log Full T-log backups required Avoids data loss due to a damaged or missing data file Recovery at specific point in time Bulk logged T-log backups required Enhance the performance of bulk copy operation Reduce log space by using minimal logging for many bulk operations
  • 23. Connect / Explore / Learn Backup Types Full Differential Transaction Log Tail Log Copy Only Partial Filegroup Snapshot
  • 24. Connect / Explore / Learn BACKUP TYPES SIMPLE FULL BULK LOGGED Full ● ● ● Differential ● ● ● Transaction Log ● ● Tail Log ● Copy Only ● ● ● Partial ● ● ● Filegroup ● ● ● Snapshot ● Backup Types / Recovery Model
  • 25. Connect / Explore / Learn Full Backup (t) New DB FULL FULL FULL
  • 26. Connect / Explore / Learn Restore Full Backup (t) New DB FULL FULL FULL t4 DAMAGE RESTORE
  • 27. Connect / Explore / Learn Differential Backup (t) New DB FULL DIFF DIFF DIFF
  • 28. Connect / Explore / Learn Restore Differential Backup (t) New DB FULL DIFF DIFF DIFF t5 DAMAGE RESTORE RESTORE
  • 29. Connect / Explore / Learn Transaction Log Backup (t) New DB FULL LOG LOG DIFF LOG LOG
  • 30. Connect / Explore / Learn Restore Transaction Log Backup (t) New DB FULL LOG LOG DIFF LOG LOG t7 DAMAGE RESTORE RESTORE RESTORE RESTORE
  • 31. Connect / Explore / Learn Tail Log Backup (t) New DB FULL LOG LOG DIFF LOG LOG DAMAGE TAIL LOG RPO A tail-log backup captures any log records which has not yet been backed up by the last transactional log backup.
  • 32. Connect / Explore / Learn Copy Only Backup (t) New DB FULL LOG LOG DIFF LOG LOG t2-3 FULL COPY ONLY
  • 33. Connect / Explore / Learn Partial Backup (t) New DB FULL Primary filegroup Read only Filegroup Read/Write Filegroup FULL READ/WRITE PARTIAL FULL READ ONLY PARTIAL DIFFERENTIAL READ/WRITE PARTIAL DIFFERENTIAL READ/WRITE PARTIAL All SQL Server recovery models support partial backups Partial backups are designed for use under the simple recovery model to improve flexibility for backing up very large databases that contain one or more read-only filegroups.
  • 34. Connect / Explore / Learn Restore Partial Backup (t) New DB FULL Primary filegroup Read only Filegroup Read/Write Filegroup FULL READ/WRITE PARTIAL FULL READ ONLY PARTIAL DIFFERENTIAL READ/WRITE PARTIAL DIFFERENTIAL READ/WRITE PARTIAL t6 DAMAGE RESTORE RESTORERESTORE
  • 35. Connect / Explore / Learn Filegroup Backup (t) New DB FULL Primary filegroup Other Filegroups FILEGROUP A FILEGROUP B FILEGROUP C FILEGROUP A FILEGROUP B FILEGROUP C t0A LOG t1A LOG t1B LOG t2A LOG t2B LOG t3A LOG t3B LOG t4A LOG t4B LOG t5A LOG t5B LOG t6A LOG t6B LOG t7A LOG t7B LOG
  • 36. Connect / Explore / Learn Restore Filegroup Backup (t) New DB FULL Primary filegroup Other Filegroups FILEGROUP A FILEGROUP B FILEGROUP C FILEGROUP A FILEGROUP B FILEGROUP C t0A LOG t1A LOG t1B LOG t2A LOG t2B LOG t3A LOG t3B LOG t4A LOG t4B LOG t5A LOG t5B LOG t6A LOG t6B LOG t7A LOG t7B LOG t8 DAMAGE FILEGROUP B t8’ TAIL LOG
  • 37. Connect / Explore / Learn 8KB Pages Database Snapshot Data file(s) Database Snapshot SELECT on Snapshot We can restore this snapshot, but it should not be considered as a backup
  • 38. Connect / Explore / Learn File-snapshot backup SQL Server instance on Azure Virtual Machine ( SQL Server 2016 + ) SQL Server Instance On Azure VM DB Azure Blob Storage (t) FULL LOG LOG LOG LOG LOG LOG LOG t9 DAMAGETAIL LOG RESTORE ALL (SEQUENCIAL) Azure Blob Storage TO URL https://<storagename>.blob.core.windows.net/<container>/xxx.bak FILE_SNAPSHOT RESTORE
  • 39. Connect / Explore / Learn When already running FULL DIFFERENTIAL LOG Full Backup Blocked Blocked Allowed ( >SQL 2005) Differential Backup Blocked Blocked Allowed ( >SQL 2005) Log Backup Allowed ( >SQL 2005) Allowed ( >SQL 2005) Blocked Backup Concurrency in the same database
  • 40. Connect / Explore / Learn Data Copy Creates files and copies data to the files Redo Phase Applies committed transactions from restored log entries Undo Phase Rolls back transactions that were uncommitted at the recovery point Phases of the Restore Process
  • 41. Connect / Explore / Learn RESTORE LABELONLY Returns information about the backup media on a specified backup device. RESTORE HEADERONLY Returns all the backup header information for all backup sets on a particular backup device. RESTORE FILELISTONLY Returns a list of data and log files contained in a backup set. RESTORE VERIFYONLY Verifies the backup but does not restore it and checks to see that the backup set is complete, and the entire backup is readable. Retrieving Backup Metadata
  • 44. Page(s) Restore Online Restore – Enterprise Edition (t) DB Full Recovery Model FULL LOG LOG DIFF LOG LOG t7 Page corruption 823, 824 PAGE(s) RESTORE RESTORE RESTORE RESTORE TAIL LOG RESTORE msdb dbo suspect_pages;
  • 45. Page(s) Restore Offline Restore – Enterprise and Standard Editions (t) DB Full Recovery Model FULL LOG LOG DIFF LOG LOG t7 Page corruption 823, 824 PAGE(s) RESTORE RESTORE RESTORE RESTORE TAIL LOG RESTORE msdb dbo suspect_pages;
  • 47. Restore to a point in time (t) DB Full Recovery Model FULL LOG LOG DIFF LOG LOG t6’ Some crucial data deleted LOG RESTORE RESTORE RESTORE RESTORE RESTORE t7’ Discover RESTORE LOG ‘<dbname>’ FROM backupdevice WITH STOPAT = ‘YYYY/MM/DD HH:MM:SS’ STOPAT = { 'datetime'| @datetime_var } STOPATMARK = { 'mark_name' | 'lsn:lsn_number’ } STOPBEFOREMARK = { 'mark_name' | 'lsn:lsn_number' } [ AFTER 'datetime'] DATA LOSS
  • 48. Connect / Explore / Learn master • Start the server instance in single-user mode by using the –m startup option. • Use a RESTORE DATABASE statement to restore a full database backup of the master database by using the sqlcmd utility. • Terminate your sqlcmd connection. • Remove the single-user startup parameter. • Restart SQL Server. model • Start the server instance with TF3608. • Use a RESTORE DATABASE statement to restore a full database backup of the master database by using the sqlcmd utility. • Terminate your sqlcmd connection. • Remove the single-user startup parameter. • Restart SQL Server. msdb • You can restore it by using the RESTORE DATABASE statement as you would a user db Restore System databases
  • 49. Connect / Explore / Learn Transaction Log Truncation T-logfile Start End End File growth
  • 50. Connect / Explore / Learn Transaction Log Truncation T-logfile Start End Start End
  • 53. Connect / Explore / Learn Differential Backup Commonly used case Restore chain too long impacting RTO
  • 54. Connect / Explore / Learn Smart differential backup New approach ( SQL Server 2016 + ) modified_extent_page_count -> sys.dm_db_file_space_usage Total number of pages modified in allocated extents of the file since last full database backup. The modified page count can be used to track differential changes in the database since last full backup to decide if differential backup is beneficial SELECT file_id, total_page_count, modified_extent_page_count, cast (( modified_extent_page_count * 1.0 / total_page_count * 1.0 ) * 100.0 as decimal(5,2)) as pctchanges FROM sys.dm_db_file_space_usage
  • 55. Connect / Explore / Learn Transaction Log Backup Commonly used case Not Adaptive • Frequent Auto grows • VLF Fragmentation • Inconsistent backup size
  • 56. Connect / Explore / Learn Smart transaction log backup New approach ( SQL Server 2016 + ) select from sys.dm_db_log_stats DB_ID Adaptive • Minimal Auto grows • No VLF Fragmentation • Consistent backup size
  • 59. Connect / Explore / Learn Memory out of buffer cache How SQL Server Backup Works DB 1 Backup command executed 2 Checkpoints (few times) Checkpoints 3 Workers creation Controller Read thread (one per volume) Write thread (one per backup device) 4 Start buffering data (async I/O) backup device BUFFER BUFFER BUFFER BUFFER BUFFER BUFFER BUFFER BUFFER 5 Writing buffered data 6 Exchange the buffers
  • 60. Connect / Explore / Learn BufferCount • Specifies the total number of I/O buffers to be used for the backup operation. • You can specify any positive integer • Large numbers of buffers might cause “out of memory” errors because of inadequate virtual address space in the Sqlservr.exe process. MaxTransferSize • Specifies the largest unit of transfer in bytes to be used between SQL Server and the backup media. • The possible values are multiples of 65536 bytes (64 KB) ranging up to 4194304 bytes (4 MB). Important Backup Options Calculate the Buffer Count Formula
  • 62. Connect / Explore / Learn Backup related wait types BACKUPBUFFER Occurs when a backup task is waiting for data or is waiting for a buffer in which to store data. BACKUPIO Occurs when a backup task is waiting for data or is waiting for a buffer in which to store data. BACKUPTHREAD Occurs when a task is waiting for a backup task to finish.
  • 64. Connect / Explore / Learn SQL Server tracks all backup activity in the following tables in the msdb database: • msdb.dbo.backupfile • msdb.dbo.backupfilegroup • msdb.dbo.backupmediafamily • msdb.dbo.backupmediaset • msdb.dbo.backupset Viewing Backup History https://bit.ly/365LosB
  • 65. Connect / Explore / Learn Deleting Backup History sp_delete_backuphistory @oldest_date sp_delete_database_backuphistory @database_name
  • 66. Connect / Explore / Learn Backup/Restore operation execution info How to know the execution percentage and completion time for a backup / restore operation SELECT SUBSTRING case when then else end DATEADD FROM sys.dm_exec_requests CROSS APPLY sys.dm_exec_sql_text INNER JOIN sys.dm_exec_sessions INNER JOIN sys.dm_exec_connections WHERE https://www.sqlschool.gr/blog/how-to-know-the-execution-percentage-and-completion-time-for-a-task-1054.aspx
  • 68. Thank you! @antoniosch - @sqlschool ./sqlschoolgr - ./groups/sqlschool ./c/SqlschoolGr SQLschool.gr Group Antonios Chatzipavlis Data Solutions Consultant & Trainer
  • 69. A community for Greek professionals who use the Microsoft Data Platform Copyright © 2010-2020 SQLschool.gr. All right reserved. PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION