MS SQL administration : Backup and Restore

How to take backup of a database

Full Backup

This backup includes mdf and ldf files.

BACKUP DATABASE <Databasename>
TO DISK = '<Destination path>'


Transaction Log Backup
This includes only the transaction log backup

BACKUP LOG <Databasename>
TO DISK = '<Destination path>'

Differential Backup
This includes all changes done after the last successfull Full backup


BACKUP DATABASE <Databasename>
TO DISK = '<Destination path>'
WITH DIFFERENTIAL

Files and File group Backup

This backup allows us to save individual SQL files


BACKUP DATABASE <Databasename> FILEGROUP='<FilegrpName>'
TO DISK = '<Destination path>'

How to restore database

Restore Full Backup



RESTORE DATABASE <Databasename>
FROM DISK = '<Destination path>'

Restore Full + Differential Backup


----Restore Full backup with NORECOVERY command-----
RESTORE DATABASE <Databasename>
FROM DISK = '<Destination path>'
WITH NORECOVERY

Norecovery command will not make the restored DB live. It will wait for the next recovery restore to complete the restoration.


----Then restore Differential backup with RECOVERY command-----

RESTORE DATABASE <Databasename>
FROM DISK = '<Destination path>'
WITH RECOVERY

If no option is specified explictly, WITH RECOVERY option will be used.


Restore Backup to a particular point of time 



RESTORE DATABASE <Databasename>
FROM DISK = '<Destination path>'
WITH RECOVERY
STOPAT='JAN01,2013 06:00:00'

This restores all transactions in the backup made till 06:00 AM 01/01/2013.


Restore Transaction Log



RESTORE LOG <Databasename>
FROM DISK = '<Destination path>'

Comments

Popular posts from this blog

VMware and Windows Interview Questions: Part 2

VMware and Windows Interview Questions: Part 3

VMware vMotion error at 14%