SQL Backups for Beginners by Mark Gordon

Slides:



Advertisements
Similar presentations
Microsoft SQL Server Architecture
Advertisements

Burt King We will cover: Essentials --No command line needed here (mott) What is SQL Server How does it come to life What are the.
Module 7 Restoring SQL Server 2008 R2 Databases. Module Overview Understanding the Restore Process Restoring Databases Working with Point-in-time Recovery.
FlareCo Ltd ALTER DATABASE AdventureWorks SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS Slide 1.
SharePoint and SQL Server integration Demo: SQL Server Optimizing Configurations SQL Server 2014 for SharePoint 2013 Avoiding ginormous transaction.
Microsoft SQL Server Administration for SAP Database Backup and Restore.
Week 9 – Chapter 8 SQL 710 Methods to Backup Databases
Database Backup and Recovery
Backup and Recovery Part 1.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Presented by Joseph Galvan & Stacy Kemp BACKUPS.  Using database backups, a database administrator (DBA’s) can restore from the last backup or to a specific.
Transaction log grows unexpectedly
Chapter 2 Administrating DB Engine. Database Engine  The Database Engine is the core service for storing, processing, and securing data.  It provides.
DBA Quick Start What do you do when you’ve fallen into a job as a DBA? Take a deep breath, Find out what you’ve got, And dive right in!
SQL Server 2008 Implementation and Maintenance Chapter 7: Performing Backups and Restores.
Chapter 10 : Designing a SQL Server 2005 Solution for High Availability MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design.
1 Chapter Overview Creating a User Database Setting Database Options Managing User Database Size Placing Database Files on Multiple Disks.
Chapter 2: Designing Physical Storage MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Module 3: Managing Database Files. Overview Introduction to Data Structures Creating Databases Managing Databases Placing Database Files and Logs Optimizing.
Chapter 7 Making Backups with RMAN. Objectives Explain backup sets and image copies RMAN Backup modes’ Types of files backed up Backup destinations Specifying.
It is one of the techniques to create a stand by server. Introduced in SQL 2000,enhanced in It is a High Availability as well as Disaster recovery.
DATABASE MIRRORING  Mirroring is mainly implemented for increasing the database availability.  Is configured on a Database level.  Mainly involves two.
Architecture Rajesh. Components of Database Engine.
Module 6 Backup of SQL Server 2008 R2 Databases. Module Overview Backing up Databases and Transaction Logs Managing Database Backups Working with Backup.
MS SQL by: Bryan Bankhead CIS 407. General Concepts  Backing up and Restoring databases and transaction logs is a way that SQL Server provides protection.
Pedro Azevedo Lopes Premier Field Engineer Microsoft Corporation.
1 Chapter Overview Understanding Data Restoration Issues Understanding the Types of Database Backups Understanding the Restoration Process.
Learningcomputer.com SQL Server 2008 – Backup and Restore Database.
Backup and Recovery - II - Checkpoint - Transaction log – active portion - Database Recovery.
Data Disaster Recovery Planning Greg Fibiger 1/7/2016.
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
DBA Quick Start What do you do when you’ve fallen into a job as a DBA? Take a deep breath, Find out what you’ve got, And dive right in!
Partial Database Availability
Turgay Sahtiyan Istanbul, Turkey
Database Administration
Transaction Log Fundamentals
Inside transaction logging
Katowice,
Curacao SQL Saturday June 11, 2016
Disaster Recovery Where to Begin
Antonio Abalos Castillo
From Basic to Something More
Building Effective Backups
Installation and database instance essentials
The Nitty-Gritty of Database Backups
Contained DB? Did it do something wrong?
From Basic to Something More
Chapter Overview Understanding the Database Architecture
Introduction to SQL Server Management for the Non-DBA
SQL Recovery Freeware is the top notch tool to recover damaged MS SQL database.
SQL Backups for Beginners by Mark Gordon
11/17/ :39 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
What’s new in SQL Server 2016 Availability Groups
Backup and Restore your SQL Server Database
Inside transaction logging
Turbo-Charged Transaction Logs
Transaction Log Fundamentals
Backup to Basics Tom Fox
Active Secondary: Enabling Backup On Secondary
Transaction Log Internals and Performance David M Maxwell
Sun Mon Tue Wed Thu Fri Sat
Performing Database Recovery
Chapter 11 Managing Databases with SQL Server 2000
Sun Mon Tue Wed Thu Fri Sat
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
Sun Mon Tue Wed Thu Fri Sat
Disaster Recovery Done Dirt Cheap Founder Curnutt Data Solutions
Backup & Recovery.
Database Backup and Recovery
Accelerated DATABASE RECOVERY
Presentation transcript:

SQL Backups for Beginners by Mark Gordon v 1.2

Getting Started Goal Bio Why Backup? You backup the db so you can restore it back from a failure. When restored, the db must be transactionally consistent.

SQL Databases When you install SQL Server there are four databases that are automatically installed. Thus, these are called System databases: Master Model MSDB TempDB These are used for different internal purposes. Do you need to back these System databases up too? Yes, except for TempDB!! TempDB gets rebuilt by SQL every time your restart SQL Server. The Master, MSDB, and Model databases might be backed-up less frequently than your own databases but business needs will drive that decision.

SQL Databases Then, there are “your” databases - the ones you create. These are called “User” databases.

SQL Database File Types Three main types of sql database files for each database: Primary data file (.mdf) – this is the primary data file (heart) of your database. It holds the actual data. Every database has one primary file. Secondary data file (.ndf). These is optional and lets you spread data into different physical disc for different reasons. We will not be discussing this one today because as beginners, you most likely are not using it. Transaction Log (.ldf) – this is the log data file. It captures change and is what sql uses to restore your database – among other things. There must be at least one log file for every database. Not easily readable. https://msdn.microsoft.com/en-us/library/ms189563.aspx

SQL Database File Types 1- Every database has at least an .mdf and .ldf. System databases too!!! 2- How does SQL process data? https://msdn.microsoft.com/en-us/library/ms189563.aspx

Transaction Log Architecture How Does It Work? It tracks change for SQL. Do not consider it an audit trail! VLF (Virtual Log File) – Unit of growth. LSN (Log Sequence Number) – Unique identifier for each log record. Write Ahead Round Robin Physical Log File Unused Unused Unused Unused Unused Unused https://technet.microsoft.com/en-us/library/ms179355(v=sql.105).aspx Virtual Log Files (VLFs)

SQL Database Recovery Model What is Point-in-Time Recovery?

SQL Database Recovery Model A recovery model is a database property that controls how transactions are logged, whether the transaction log requires (and allows) backing up, and what kinds of restore operations are available https://msdn.microsoft.com/en-us/library/ms189275(v=sql.110).aspx

SQL Database Recovery Model There are three database recovery models: Simple: Provides NO point-in-time recovery. Truncates Log On Checkpoint !!!!! No separate transaction log backups. When you make a backup and you need to recover data, you only have the database recoverable to the point of a backup. Full: Gives you the capability for Point in time recovery. When you have log backups, you get point in time recovery. Commonly used for OLTP applications. Requires separate transaction log backups. Bulk -logged: Similar to Full. Can have separate transaction log backups but is normally used “temporarily” for special bulk loading operations. It reduces the amount of logging it performs during bulk load operations.

SQL Database Recovery Model It is the database that has the recovery model. Thus, a database can have one of the three recovery models: Simple Full Bulk-logged The recovery model can be changed. But, this requires further discussion as to why and when you would do this. Altering the recovery model may have an impact on your backup approach. https://msdn.microsoft.com/en-us/library/ms189275(v=sql.130).aspx

SQL Database Recovery Model What is the default Recovery Model?

SQL Database Backup Types There are three main backup types: Full Differential Transaction Log There are actually others but we will focus only on these today.

SQL Database Backup Types Full This is a complete backup of the database – both data file (MDF/NDF) and transaction log (LDF). This includes part of the transaction log so that the database can be recovered, if needed. If recovery is needed, you will end up with a transactionally consistent database when done.

SQL Database Recovery Model Restore – With Full Backup What could I restore? Full Backup Sunday 12:00 AM Full Backup Sunday 12:00 AM Fri Mon Wed Tue Thu Sat

SQL Database Backup Types Differential A differential backup is based on the most recent/previous FULL data backup. A differential backup captures only the data that has changed since that last full backup. The full backup upon which a differential backup is based is known as the base of the differential. In SQL Server 2005 and later versions, differential file backups can be very fast because the SQL Server Database Engine tracks the changes that were made since the differential base was created. https://technet.microsoft.com/en-us/library/ms175526(v=sql.130).aspx

SQL Database Recovery Model Restore – With Full And Diff What could I restore? Full Backup Sunday 12:00 AM Full Backup Sunday 12:00 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Fri Mon Wed Tue Thu Sat

SQL Database Backup Types Transaction Log Backup Used for the point-in-time recovery. Not applicable for Simple Recovery. Simple is Truncate On CheckPoint!!! You must back-up the transaction log separately from a Full or Diff backup. What is active/inactive transactions? When the separate transaction log backup occurs, the inactive portion of the transaction log is truncated. In Full or Bulk, the inactive part of the log cannot be truncated until all its log records have been captured in a log backup. Just because you do a Full backup “does not” mean you have truncated the inactive part of the transaction log – YOU HAVEN’T. Thus, when in FULL recovery mode, you must do transaction log backups. https://technet.microsoft.com/en-us/library/ms189085(v=sql.105).aspx

Transaction Log Architecture Full Recovery Perform Trans Log Backup (2 steps occur) https://msdn.microsoft.com/en-us/library/jj835093(v=sql.120).aspx

SQL Database Recovery Model Full Recovery – With Full And Diff No Transaction Log Backup (Danger!) Full Backup Sunday 12:00 AM Full Backup Sunday 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Trn Trn Trn Trn Trn Trn Trn Fri Mon Wed Tue Thu Sat

SQL Database Recovery vs Backup Type Key Points There are database recovery models that the database operates with: Simple Full Bulk-logged Then there are database backup types : Differential Transaction log Just remember that if a database is in simple recovery, you do not get a transaction log backup. This is because the transaction log gets truncated many times during processing and does not give you point in time recovery – that is why it is called SIMPLE.

SQL Database Recovery Model vs Backup Type Full Backup Diff Backup Transaction Log Backup Simple Y N Full https://msdn.microsoft.com/en-us/library/ms189275(v=sql.110).aspx

SQL Database Restoring When you restore a database, you must start restoring from a Full backup. What you do after that depends on the recovery model and what you are needing to do. Plan out what you need to do before you start.

SQL Database Recovery Model Simple Recovery – With Full Backup Full Backup Sunday 12:00 AM Full Backup Sunday 12:00 AM Fri Mon Wed Tue Thu Sat

SQL Database Recovery Model Simple Recovery – With Full And Diff Full Backup Sunday 12:00 AM Full Backup Sunday 12:00 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Fri Mon Wed Tue Thu Sat

SQL Database Recovery Model Full Recovery – With Full Backup No Diff and No Trans Log Backup Full Backup Sunday 12:00 AM Full Backup Sunday 12:00 AM Trn Trn Trn Trn Trn Trn Trn Fri Mon Wed Tue Thu Sat

SQL Database Recovery Model Full Recovery – With Full And Diff No Transaction Log Backup Full Backup Sunday 12:00 AM Full Backup Sunday 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Trn Trn Trn Trn Trn Trn Trn Fri Mon Wed Tue Thu Sat

SQL Database Recovery Model Full Recovery – With Full and Transaction backup (log chain)!! Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Full Backup Sunday 12:00 AM Full Backup Sunday 12 AM Trn Trn Trn Trn Trn Trn Trn Fri Mon Wed Tue Thu Sat

SQL Database Recovery Model Full Recovery – With Full, Diff and Transaction backup (log chain)!! Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Trn BU 6 PM Full Backup Sunday 12:00 AM Full Backup Sunday 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Diff 12 AM Trn Trn Trn Trn Trn Trn Trn Fri Mon Wed Tue Thu Sat

SQL Database Key Points Simple Recovery – No point-in-time recovery. Full Recovery with transaction log backups give point-in-time recovery opportunity. Everything starts with a FULL backup! When you restore a database you must start from a Full backup.

SQL Database Demo Simple Recovery Model: Full and Diff bu Restore Full Recovery Model: Full and Trans bu

Switching Recovery Models: SQL Database Switching Recovery Models: Always do a Full or Diff backup after changing recovery models from Simple-to-Full or Full-to-Simple. Switching from Simple-to-Full, it must start the log chain. Thus, Full or Diff backup is needed; it will start the backup log chain when you do the Full or Diff bu. I like doing Full bu. Switching from Full-to-Simple, breaks the backup log chain. Thus Full or Diff backup is needed. I like doing Full bu. Note: If you switch from Simple Recovery to Full Recovery, it will still behaves as Simple until you do a Full or Diff backup! https://technet.microsoft.com/en-us/library/ms178052(v=sql.105).aspx

Resources SQL BOL https://technet.microsoft.com/en-us/magazine/2009.07.sqlbackup.aspx http://www.sqlskills.com/blogs/paul/a-sql-server-dba-myth-a-day-3030-backup-myths/ https://technet.microsoft.com/en-us/library/ms189085%28v=sql.105%29.aspx https://msdn.microsoft.com/en-us/library/ms179314(v=sql.105).aspx (tail of the log) https://technet.microsoft.com/en-us/library/ms190440(v=sql.105).aspx (log chain backup) Great link from Grant Fritchey showing how to do a backup and restore: https://www.youtube.com/watch?v=pA242aMvz6E

Questions ? Email: markgordonnc@nc.rr.com