week 9 – chapter 8 - methods to backup databases - types of data to be backed up - recovery models...
TRANSCRIPT
![Page 1: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/1.jpg)
Week 9 – Chapter 8
- Methods to Backup Databases
- Types of data to be backed up
- Recovery models
- Recovery methods
![Page 2: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/2.jpg)
Methods to Back up Data
• Maintenance Wizard (Chapter 7) to create maintenance plan with scheduled backups
• Enterprise Manager to schedule job to perform backup or to perform unscheduled backup as required
• T-SQL commands
• Specialized packages such as Backup Exec or Arcserv (not discussed here)
![Page 3: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/3.jpg)
Prevent Loss of Data
Have a strategy:1.To minimize data loss (malicious use of
delete, update statement, viruses, natural disaster, theft)
2.To recover lost data3.To restore data with minimal cost and
impactBackup regularly:
1.Backup frequently if your database is OLTP
2.Backup less frequently if your database is OLAP
![Page 4: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/4.jpg)
Database Recovery Models
Set Database Recovery Model:• Full Recovery Model • Bulk logged recovery model• Simple Recovery Model
Modify a database recovery model1.Alter database pubs 2.Set recovery to bulk_logged
![Page 5: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/5.jpg)
Backups
• SQL Server allows backups to occur while users continue to work with the database
• Backs up original files and records their locations
• Captures in the backup all database activities that occur during the backup process
![Page 6: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/6.jpg)
Who can perform backup?1.Members of the sysadmin fixed server role2.Members of the db_owner and
db_backupoperators fixed database roles
Where to store backup?1.Hard disk file2.Tape3.A location identified by a Named Pipe (3rd
party software package)
Backups (ctd)
![Page 7: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/7.jpg)
When to backup System Databases
• After modifying the master database:• Using CREATE DATABASE, ALTER
DATABASE or DROP statement• Executing certain Stored Procedures
• After modifying the msdb database• After modifying the model database
![Page 8: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/8.jpg)
When to backup User Databases
• After creating a database• After creating an index• After creating a transaction• After performing un-logged operations:
• BACKUP WITH TRUNCATE_ONLY OR NO_LOG OPERATIONS
• SELECT INTO statement
![Page 9: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/9.jpg)
Restricted Activities during backup
• Creating or modifying database• Performing autogrow operations• Creating indexes• Performing non-logged options• Shrinking a database
![Page 10: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/10.jpg)
Create a Backup device
• A backup file that is created before it is used for a backup is called a backup device
• Why create permanent backup devices?• To reuse backup files for future
backups• To automate the backup
![Page 11: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/11.jpg)
Create a Backup device(ctd)
Use sp_addumpdevice system procedure:• Specify a logical name• Logical and physical Names are stored in the
sysdevices system table
Example:Use masterExec sp_addumpdevice ‘disk’ , ‘mybackupfile’, ‘c:\Backup|mybackupfile.bak’
![Page 12: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/12.jpg)
Perform Backup without backup device
Why create backup without backup device?• To perform one time backup• To test backup operation that you plan to
automateHow to use backup database statement:
• Specify the media type (disk, tape, or Named Pipe)
• Specify the complete path and full Name
Example:Use masterBackup database NorthwindTo Disk = ‘c:\temp\mycustomers.bak’
![Page 13: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/13.jpg)
Types of Backup Methods
• Full database backup
• Differential backup
• Transaction log backup
• File or File group backup
![Page 14: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/14.jpg)
Full Database Backup
• Provides a baseline
• Backs up original files, objects and data
• Backs up portions of the transaction log
Example:
Use master
Exec sp_addumpdevice ‘disk’, ‘NwindBac’ ,
‘D:\mybackupdir\Nwindbac.bak’
Backup database Northwind to NwindBac
![Page 15: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/15.jpg)
Full Database Backup Options
WITH INIT: overwrites any previous backup on that file
WITH NOINIT : appends the full database backup to the backup file. Any previous backup left intact.
![Page 16: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/16.jpg)
Differential database backup
• Use on frequently modified databases• Requires a full database backup before• Backs up database changes since the last full
database backup• Saves time in both backup and restore
processes
Example:Backup Database NorthwindDisk = ‘D:\Mydata|Mydiffbackup.bak’WITH DIFFERNTIAL
![Page 17: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/17.jpg)
Transaction log backup
• Requires a Full database backup
• Backs up all database changes from the last BACKUP LOG statement to the end of the current Transaction log.
• Truncates the transaction log
Example:Use master
Exec sp_addumpdevice ‘disk’, ‘Nwindbaclog’,
‘D:\Baclup\Nwind backuplog.bak’
Backup log Northwind To NwindBaclog
![Page 18: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/18.jpg)
Backup using No-truncate Option
No-truncate option:
• Saves the entire Transaction log even if the database is inaccessible
• Doesn’t purge the Transaction log of committed Transactions
• Allows data to be recovered up to time of system failure
![Page 19: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/19.jpg)
Clear the Transaction log
• Use Backup statement to clear transaction log
• Use truncate only or no_log option• Can’t recover changes• Is not recorded changes
![Page 20: Week 9 – Chapter 8 - Methods to Backup Databases - Types of data to be backed up - Recovery models - Recovery methods](https://reader035.vdocuments.site/reader035/viewer/2022072009/56649d8d5503460f94a76312/html5/thumbnails/20.jpg)
Database file or filegroup backup
1.Use on very large databases
2.Backup the database files individually
3.Ensure that all database files in File group are backed up
4.Back up transaction log
Example:
Backup database phoneorders
File = Orders2 To orderbackup2
Backup log phoneOrders to orderlog