Wednesday, 20 November 2013

Best Practices for Backup and Restore in SQL Server 2005



Backup Targets

Besides the backup type, SQL Server allows four different backup targets: Database, Filegroup, File and Partial. These targets only apply to the Full and Differential Backup types; they do not apply to the log backup.

Database Backup

A database backup makes a copy of the entire database. If you are using a Full database backup it includes all used database pages in the database; if you are using a Differential Database backup, it includes all changed database pages of the database that have changed since the last full backup. Some examples of how to perform a Full and Differential Database backup are:

-- Full Database Backup

BACKUP DATABASE AdventureWorks
  TO  DISK = N’C:\Backup\AdventureWorks.bak’ 

-- Differential Database Backup

BACKUP DATABASE AdventureWorks
  TO  DISK = N’C:\Backup\AdventureWorks.bak’
  WITH DIFFERENTIAL

Differential Backup

Differential backups are designed to reduce the amount of time it takes to perform full backups. Instead of copying all used pages, the differential backup copies only pages that have changed since the last full backup. Similar to the Full Backup, differential backups also copy a part of the transaction log to maintain the transactional integrity when the backup is restored. The following code is an example of how to create a Differential Backup. 

BACKUP DATABASE AdventureWorks
  TO DISK = N’C:\Backup\AdventureWorks.bak’
  WITH DIFFERENTIAL

Log Backup

The only type of backup that does not actually copy database pages is the Log backup. The Log backup copies the transaction log of the database. After it copies the log, the backup truncates the part of the log that is not required by active transactions or transactional replication. The syntax to back up the Log is:
BACKUP LOG AdventureWorks
TO  DISK = N’C:\Backup\AdventureWorks.bak’


File Backup

File backups do not copy the database; instead the file backup aim is to back up only one or more files that are part the database.Databases in SQL server 2005 have three different types of files: Primary, Secondary, or Log Files. Primary and Secondary files hold database pages; in contrast, Log files hold the transaction log. File backups can make copies of pages from Primary and Secondary Files.This type of backup can be used to speed up the restora-tion process, when the device that stores one of the files
fails but the rest of the devices are working correctly. In this case, there is no need to restore the full database; only the affected file.  The following SQL code performs Full and Differential File backups:

-- Full File Backup

BACKUP DATABASE AdventureWorks  FILE=’AdventureWorks_Data’
TO  DISK = N’C:\Backup\AdventureWorks.bak’ 

-- Differential File Backup

BACKUP DATABASE AdventureWorks  FILE=’AdventureWorks_Data’
TO  DISK = N’C:\Backup\AdventureWorks.bak’
  WITH DIFFERENTIAL

One important element to remember when using File Backups is that they should either be read only (the file-group they belong to) or combined with Log Backups to restore transactional integrity of the database. File backups do not automatically back up the transaction log.
 

What are the basic functions for master, msdb, model, tempdb and resource databases?

What are the basic functions for master, msdb, model, tempdb and resource databases?
The master database holds information for all databases located on the SQL Server instance and is the glue that holds the engine together. Because SQL Server cannot start without a functioning master database, you must administer this database with care.

The msdb database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server jobs, and some replication information such as for log shipping.

The tempdb holds temporary objects such as global and local temporary tables and stored procedures.

The model is essentially a template database used in the creation of any new user database created in the instance.

The resoure Database is a read-only database that contains all the system objects that are included with SQL Server. SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically appear in the sys schema of every database. The Resource database does not contain user data or user metadata.

What is Service Broker?

Service Broker is a message-queuing technology in SQL Server that allows developers to integrate SQL Server fully into distributed applications. Service Broker is feature which provides facility to SQL Server to send an asynchronous, transactional message. it allows a database to send a message to another database without waiting for the response, so the application will continue to function if the remote database is temporarily unavailable.

Where SQL server user names and passwords are stored in SQL server?

They get stored in System Catalog Views sys.server_principals and sys.sql_logins.