SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
Antonios Chatzipavlis
DATA SOLUTIONS CONSULTANT & TRAINER
SQL Server Backup/Restore Revealed
SQL Night #43
Sep 26, 2020
20:30
SQL Nights
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
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

Weitere ähnliche Inhalte

Was ist angesagt?

Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architecture
Naveen Boda
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overview
honglee71
 
JPA and Coherence with TopLink Grid
JPA and Coherence with TopLink GridJPA and Coherence with TopLink Grid
JPA and Coherence with TopLink Grid
James Bayer
 

Was ist angesagt? (20)

Sql server 2016 new features
Sql server 2016 new featuresSql server 2016 new features
Sql server 2016 new features
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
How to think like the engine
How to think like the engineHow to think like the engine
How to think like the engine
 
SQL Server 2012 Best Practices
SQL Server 2012 Best PracticesSQL Server 2012 Best Practices
SQL Server 2012 Best Practices
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management System
 
Microsoft SQL Server 2016 - Everything Built In
Microsoft SQL Server 2016 - Everything Built InMicrosoft SQL Server 2016 - Everything Built In
Microsoft SQL Server 2016 - Everything Built In
 
SQL Server R Services: What Every SQL Professional Should Know
SQL Server R Services: What Every SQL Professional Should KnowSQL Server R Services: What Every SQL Professional Should Know
SQL Server R Services: What Every SQL Professional Should Know
 
Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101Geek Sync | SQL Security Principals and Permissions 101
Geek Sync | SQL Security Principals and Permissions 101
 
SQL Server 2016: Just a Few of Our DBA's Favorite Things
SQL Server 2016: Just a Few of Our DBA's Favorite ThingsSQL Server 2016: Just a Few of Our DBA's Favorite Things
SQL Server 2016: Just a Few of Our DBA's Favorite Things
 
Oracle Database 12c - Features for Big Data
Oracle Database 12c - Features for Big DataOracle Database 12c - Features for Big Data
Oracle Database 12c - Features for Big Data
 
SQL Server 2016 Editions
SQL Server 2016 Editions SQL Server 2016 Editions
SQL Server 2016 Editions
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017
 
Spark
SparkSpark
Spark
 
Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architecture
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overview
 
Connecting Hadoop and Oracle
Connecting Hadoop and OracleConnecting Hadoop and Oracle
Connecting Hadoop and Oracle
 
JPA and Coherence with TopLink Grid
JPA and Coherence with TopLink GridJPA and Coherence with TopLink Grid
JPA and Coherence with TopLink Grid
 
SQL Server 2016 BI updates
SQL Server 2016 BI updatesSQL Server 2016 BI updates
SQL Server 2016 BI updates
 

Ähnlich wie SQL server Backup Restore Revealed

Administration and Management of Users in Oracle / Oracle Database Storage st...
Administration and Management of Users in Oracle / Oracle Database Storage st...Administration and Management of Users in Oracle / Oracle Database Storage st...
Administration and Management of Users in Oracle / Oracle Database Storage st...
rajeshkumarcse2001
 
Less14 Br Concepts
Less14 Br ConceptsLess14 Br Concepts
Less14 Br Concepts
vivaankumar
 
2011 384 hackworth_ppt
2011 384 hackworth_ppt2011 384 hackworth_ppt
2011 384 hackworth_ppt
maclean liu
 

Ähnlich wie SQL server Backup Restore Revealed (20)

Backup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL ServerBackup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL Server
 
Les 06 Perform Rec
Les 06 Perform RecLes 06 Perform Rec
Les 06 Perform Rec
 
Administration and Management of Users in Oracle / Oracle Database Storage st...
Administration and Management of Users in Oracle / Oracle Database Storage st...Administration and Management of Users in Oracle / Oracle Database Storage st...
Administration and Management of Users in Oracle / Oracle Database Storage st...
 
Less14 Br Concepts
Less14 Br ConceptsLess14 Br Concepts
Less14 Br Concepts
 
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
24 HOP edición Español - Sql server 2014 backup encryption - Percy Reyes
 
Take your database source code and data under control
Take your database source code and data under controlTake your database source code and data under control
Take your database source code and data under control
 
5 backuprecoveryw imp
5 backuprecoveryw imp5 backuprecoveryw imp
5 backuprecoveryw imp
 
SQL Operations : Part 3 (Database Restore & Database Shrink) - SLT
SQL Operations : Part 3 (Database Restore & Database Shrink) - SLTSQL Operations : Part 3 (Database Restore & Database Shrink) - SLT
SQL Operations : Part 3 (Database Restore & Database Shrink) - SLT
 
ORACLE ARCHITECTURE
ORACLE ARCHITECTUREORACLE ARCHITECTURE
ORACLE ARCHITECTURE
 
TAFJ
TAFJTAFJ
TAFJ
 
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007Tech Ed Africa Demystifying Backup Restore In Share Point 2007
Tech Ed Africa Demystifying Backup Restore In Share Point 2007
 
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
Techedafricademystifyingbackuprestoreinsharepoint2007 090805103250 Phpapp02
 
Les 05 create_bu
Les 05 create_buLes 05 create_bu
Les 05 create_bu
 
2011 384 hackworth_ppt
2011 384 hackworth_ppt2011 384 hackworth_ppt
2011 384 hackworth_ppt
 
Oracle Database Backup
Oracle Database BackupOracle Database Backup
Oracle Database Backup
 
SQL Server - High availability
SQL Server - High availabilitySQL Server - High availability
SQL Server - High availability
 
Xpp c user_rec
Xpp c user_recXpp c user_rec
Xpp c user_rec
 
Les 05 Create Bu
Les 05 Create BuLes 05 Create Bu
Les 05 Create Bu
 
Twitter's Data Replicator for Google Cloud Storage
Twitter's Data Replicator for Google Cloud StorageTwitter's Data Replicator for Google Cloud Storage
Twitter's Data Replicator for Google Cloud Storage
 
Databaseadmonfundamentalitprosdcchapter6
Databaseadmonfundamentalitprosdcchapter6Databaseadmonfundamentalitprosdcchapter6
Databaseadmonfundamentalitprosdcchapter6
 

Mehr von Antonios Chatzipavlis

Mehr von Antonios Chatzipavlis (20)

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

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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
  • 2.
  • 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
  • 6.
  • 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