SQL Server Backups Part1 Questions
SQL Server Backups Part1 Questions
A Database backup is a copy of SQL Server data that can be used to restore and recover the
data in case of any failure. A backup of SQL Server data is created at the level of a database or
one or more of its files or filegroups. There is another option to take Transaction Log backups
when the database recovery model of a database is Full.
Full Backup
Differential Backup
Transaction Log Backup
Copy-Only Backup
File or Filegroup Backup
A full backup is a backup of the entire database that contains all the data and log file records
needed to recover the database to the point in time when backup completed. Full backup should
be a part of backup strategy for all the business-critical databases.
Full database backup contains the complete set of data needed to restore and recover a
database to a consistent state. It serves as a baseline for all other backups.
Differential backup backups up only the data that has changed since the last full backup. A
differential backup is not a stand-alone backup it needs a full backup to act as a baseline. For
larger databases differential backups is common in order to save space and reduce the backup
time.
In addition to being smaller and faster than full backup, a differential backup makes the restore
process simpler. When you restore using differentials you must first restore the full backup
followed by the most recent differential backup that was taken.
--Back up the AdventureWorks as differential backup
BACKUP DATABASE AdventureWorks TO DISK = N'c:\AdventureWorksDiff.bak' WITH
DIFFERENTIAL
Log backups can be taken only if the recovery model of the database is Full recovery or Bulk-
logged recovery. Simple recovery model does not allow transaction log backup because the log
file is truncated automatically upon database checkpoints.
Log backups are taken between full backups to allow point-in-time recovery with the exception of
log backups containing bulk-logged records. Without Transaction log backups you can restore
data only till the time when the full or differential backup was taken.
Using the file or filegroup backup you can backup an entire filegroup or files within the filegroup.
These backups are essential when the database size is so large that backups must be done in
parts because it takes too long to backup the entire database. Another potential benefit of having
filegroup backups is that if the disk on which a particular file resides fails and is replaced, just the
file can be restored instead of the entire database.
Copy-only backups are introduced in SQL Server 2005 and are used to create a full database or
transaction log backup without breaking the log chain. A copy-only full backup can’t be used as a
basis for a differential backup, nor can you create a differential copy only backup.
Mirrored database backups can be used to create multiple copies of the database backups on
different locations.
A tail-log backup captures any log records that have not yet been backed up (the tail of the log)
to prevent work loss and to keep the log chain intact. Before you can recover a SQL Server
database to its latest point in time, you must back up the tail of its transaction log. The tail-log
backup will be the last backup of interest in the recovery plan for the database.
12) How can you enable Database compression on all the native backups?
Backup compression can be enabled at the SQL Server instance level as below.
USE master;
GO
EXEC sp_configure 'show advanced option', '1';
RECONFIGURE
GO
EXEC sp_configure 'backup compression default', '1';
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure 'show advanced option', '0';
RECONFIGURE
GO
13) Is it possible to add password to a backup file in SQL Server 2012 version?
WITH password option is not available any more with SQL Server 2012 onwards.
backup database
Transaction Log backups are possible in Full and Bulk Logged recovery model.
15) What all operations are minimally logged when the database is in Bulk Logged
Recovery mode?
Bulk import operations (bcp, BULK INSERT, and INSERT… SELECT). For more
information about when bulk import into a table is minimally logged.
SELECT INTO operations.
Partial updates to large value data types, using the .WRITE clause in the UPDATE
statement when inserting or appending new data. Note that minimal logging is not used
when existing values are updated.
WRITETEXT and UPDATETEXT statements when inserting or appending new data into
the text, ntext, and image data type columns. Note that minimal logging is not used when
existing values are updated.
CREATE INDEX operations (including indexed views).
ALTER INDEX REBUILD or DBCC DBREINDEX operations.
DROP INDEX new heap rebuild (if applicable).
We can use RESTORE VERIFY ONLY command to make sure that the Database backups are
restorable.
17) What is the database that has the backup and restores system tables?
18) What are the backup and restore system tables? What do each of the tables do?
Here are the backup and restore system tables and their purpose:
backupfile – contains one row for each data file or log file backed up
backupmediafamily – contains one row for each media family
backupmediaset – contains one row for each backup media set
backupset – contains one row for each backup set
restorefile – contains one row for each restored file
restorefilegroup – contains one row for each restored filegroup
restorehistory – contains one row for each restore operation
19) For differential backups, how is the modifed data determined for those backups?
DCM page contains information about the extent which are changed after the Full backup. Diff.
backup process reads information about the changed extents and those extents are added in the
differential backup.
20) In a situation with full, differential and transaction log backups being issued for a
database, how can an out of sequence full backup be issued without interrupting the
LSN’s?
21) How can I verify that backups are occurring on a daily basis?
We can verify the backup history of the database that backups are happening or not.
22) What is the meaning of the values in Type column in backupset table.
D = Database
I = Differential database
L = Log
F = File or filegroup
G =Differential file
P = Partial
Q = Differential partial
Backup:
24) Is there any option to prevent All successful SQL Server backup entries from writing
to the SQL Server Error Log?
25) Assume that we have to take a backup of the database with a backup size of 90 GB.
There is no space available in a single disk drive instead there are 4 different drives where
we have 25 GB free space on each drive. How can you perform the backup to three
different drives?
USE master
GO
BACKUP DATABASE [Test] TO
DISK = N'D:\ Backups\ test_full_native_1.bak'
WITH FORMAT, INIT,
NAME = N'test- Full Database Backup',
SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
FORMAT – This option tells SQL Server whether or not to overwrite the media header
information. The FORMAT option will erase any information in a backup set that already
exists when the backup is initialized (NOFORMAT will preserve it).
INIT – By default, when scripting a backup generated by the Backup wizard, this
parameter will be set to NOINIT, which lets SQL Server know not to initialize a media set
when taking the backup and instead append any new backup data to the existing backup
set. However, since we adopt the rule of one backup per backup set, it’s useful to use
INIT instead, to make sure that, if a command gets run twice, we overwrite the existing
set and still end up with only one backup in the set.
NAME – The NAME parameter is simply used to identify the backup set. If it is not
supplied, the set will not record a name.
SKIP – Using the SKIP parameter will cause SQL Server to skip the expiration check that
it normally does on the backup set. It doesn’t care if any backups existing in the backup
set have been marked for availability to be overwritten.
NOREWIND – This parameter will cause SQL Server to keep a tape device open and
ready for use when the backup operation is complete. This is a performance boost to
users of tape drives since the tape is already at the next writing point instead of having to
search for the correct position. This is obviously a tape-only option.
NOUNLOAD – When backing up to a tape drive, this parameter instructs SQL Server not
to unload the tape from the drive when the backup operation is completed.
An enhancement introduced in SQL Server 2012 SP1 Cumulative Update 2 is enable backup
and restore from the Windows Azure Blob storage service from SQL Server using TSQL
28) What are the limitations with Windows Azure Blob storage service?
You request a file backup of specific files, but one of the files is not online. The operation
fails. To back up the online files, you can omit the offline file from the file list and repeat
the operation.
You request a partial backup, but a read/write filegroup is offline. Because all read/write
filegroups are required for a partial backup, the operation fails.
We request a full database backup, but one filegroup of the database is offline. Because
all filegroups are implicitly included in a full database backup, this operation fails.To back
up this database, you can use a file backup and specify only the filegroups that are
online.
30) What all operations are prohibited when the database backups are running?
Operations that cannot run during a database backup or transaction log backup include the
following:
File-management operations such as the ALTER DATABASE statement with either the
ADD FILE or REMOVE FILE options.
Shrink database or shrink file operations. This includes auto-shrink operations.
If you try to create or delete a database file while a backup operation is in progress, the
create or delete operation fails.
SQL Server supports three types of checksums: a checksum on pages, a checksum in log
blocks, and a backup checksum. When generating a backup checksum, BACKUP verifies that
the data read from the database is consistent with any checksum or torn-page indication that is
present in the database.
The BACKUP statement optionally computes a backup checksum on the backup stream; if page-
checksum or torn-page information is present on a given page, when backing up the page,
BACKUP also verifies the checksum and torn-page status and the page ID, of the page. When
creating a backup checksum, a backup operation does not add any checksums to pages. Pages
are backed up as they exist in the database, and the pages are unmodified by backup.