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>
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
Files and File group Backup
This backup allows us to save individual SQL files
How to restore database
Restore Full Backup
Restore Full + Differential Backup
----Restore Full backup with NORECOVERY command-----
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-----
If no option is specified explictly, WITH RECOVERY option will be used.
Restore Backup to a particular point of time
This restores all transactions in the backup made till 06:00 AM 01/01/2013.
Restore Transaction Log
Differential Backup
This includes all changes done after the last successfull Full backup
BACKUP DATABASE <Databasename>
TO DISK = '<Destination path>'
WITH DIFFERENTIALTO DISK = '<Destination path>'
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
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
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'
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
Post a Comment