Wednesday, February 1, 2012

Better SQL Server database backup

Sometimes when I restore SQL Server database from a BAK file, I get huge log file or even fail to complete the task due to lack of disk space, but it could be solved if the backup of the database was generated with small log file.

So, before you backup SQL Server database, do the following: Detach from the database. This will allow you to handle database files without SQL Server locking the files.

Then you should delete the log file. Please note that it may be better to put the file in temporary location, just in case you have many files with similar names.

Now attach the main database file again.

Note that it includes a reference to the deleted log file.

Remove the 'Not Found' log file and complete the re-attachment. This will generate new, very small, log file. Now go ahead and backup the database. When you will have much better file to restore.
 
HTML Hit Counter