0% found this document useful (0 votes)
2 views

BACKUP AND RESTORE

The document outlines the importance of backup and restore mechanisms in Microsoft SQL Server to prevent data loss and ensure compliance. It details various types of backups, including full, differential, and transaction log backups, along with recommended strategies such as the 3-2-1 rule. Practical SQL commands for performing backups and restores are provided to illustrate the processes involved.

Uploaded by

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

BACKUP AND RESTORE

The document outlines the importance of backup and restore mechanisms in Microsoft SQL Server to prevent data loss and ensure compliance. It details various types of backups, including full, differential, and transaction log backups, along with recommended strategies such as the 3-2-1 rule. Practical SQL commands for performing backups and restores are provided to illustrate the processes involved.

Uploaded by

sammbilizi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

BACKUP AND RESTORE

Introduction
• Data loss can be a catastrophic event for any organization.
• Microsoft SQL Server provides robust backup and recovery
mechanisms to safeguard critical data.
Why Backup is Crucial
• Data Recovery: Restore data after accidental deletion, hardware
failures, or software corruption.
• Disaster Recovery: Recover from major disasters like fires, floods, or
cyberattacks.
• Compliance: Meet regulatory requirements for data retention and
security.
• Testing and Development: Create copies of databases for testing and
development purposes without affecting production data.
Types of SQL Server Backups
1.Full Backup:
A complete copy of the entire database.
Time-consuming but provides a complete restore point.
Typically performed less frequently.
2.Differential Backup:
Backs up only the changes made since the last full backup.
Faster than full backups.
Requires a recent full backup for recovery.
3.Transaction Log Backup:
Captures changes made to the database since the last transaction log backup.
Used for point-in-time recovery.
Essential for high-availability solutions.
Backup Strategies
• 3-2-1 Rule:
3 copies of your data.
2 different media types (e.g., disk and tape).
1 off-site copy for disaster recovery.
• Backup Frequency:
Determine backup frequency based on data criticality and recovery time objectives
(RTO).
Consider factors like business hours and transaction volume.
• Backup Destinations:
• Local disk, network shared folders, tape drives, cloud storage (Azure Blob
Storage, AWS S3).
Practical Examples
1. Full Database Backup:
SQL
BACKUP DATABASE MyDatabase
TO DISK = 'C:\Backups\MyDatabase_Full.bak'
WITH INIT, FORMAT, COMPRESSION;

INIT:
Overwrites any existing data on the backup media.
Ensures a clean slate for the new backup.
Useful for full backups to prevent issues with old backup data.
FORMAT:
Similar to INIT, prepares the backup media for a new backup.
Removes any existing backup sets on the media.
COMPRESSION:
Reduces the size of the backup file.Saves storage space.
Can improve backup and restore performance
2. Differential Database Backup:
SQL
BACKUP DATABASE MyDatabase
TO DISK = 'C:\Backups\MyDatabase_Diff.bak'
WITH DIFFERENTIAL, COMPRESSION;
• WITH DIFFERENTIAL OPTION
• Specifies that the backup should be a differential backup.
• Only backs up the changes made since the last FULL backup of the
database.Faster than full backups.
• Requires a recent full backup for recovery.
3. Transaction Log Backup:
SQL
BACKUP LOG MyDatabase
TO DISK = 'C:\Backups\MyDatabase_Log.trn'
WITH NO_TRUNCATE, COMPRESSION;

WITH NO_TRUNCATE
Used with TRANSACTION LOG backups.
Prevents the transaction log from being truncated after the backup is taken.
This is crucial for scenarios like:
Log Shipping: Replicating transaction logs to a standby server.
Point-in-Time Recovery: Restoring the database to a specific point in time.
Restore Scenarios
Full Database Restore:
SQL

RESTORE DATABASE MyDatabase


FROM DISK = 'C:\Backups\MyDatabase_Full.bak'
WITH REPLACE, RECOVERY;
Differential Restore:
SQL
RESTORE DATABASE MyDatabase
FROM DISK = 'C:\Backups\MyDatabase_Full.bak'
WITH FILE = 1, NORECOVERY
RESTORE DATABASE MyDatabase
FROM DISK = 'C:\Backups\MyDatabase_Diff.bak'
WITH FILE = 1, RECOVERY;
• The WITH FILE = 1 option specifies that the backup file is for the
primary file group of the database.
• The RECOVERY option brings the database online and makes it
available for use.
• The NORECOVERY option indicates that the restore process should
not bring the database online yet. This is typically done when applying
multiple backups sequentially.

You might also like