Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

566


Part V: Enterprise Data Management


If the data fi le of the user database and master database is damaged and the transaction
log is not damaged, to minimize data loss you can still backup the tail of the transaction
log as follows:


  1. Rename the transaction log fi le. Do not delete this fi le as you will be using it again
    later in this procedure.

  2. Rebuild the master database with the command line setup.
    For detailed instructions on how to do this see http://msdn.microsoft.com/
    en-us/library/dd207003.aspx#RebuildProcedure

  3. Reapply any SQL Server updates or service packs that were previously applied.

  4. Create a new user database. The number of data and log fi les need to match the fi les
    of the damaged database. The size of the fi les can be different.

  5. Stop SQL Server.

  6. Delete data fi les of the new database, and replace the log fi les with the original
    transaction log fi les.

  7. Start SQL Server.

  8. The new database will fail to recover because you deleted the data fi le. Run the fol-
    lowing command to back up the tail of the log:
    BACKUP LOG Databasename
    TO DISK = 'file location'
    WITH NO_TRUNCATE;


If only the data fi les of the user database are damaged and the master database and transaction log fi le of the user
database are available, the tail of the log can be backed up directly by running the preceding BACKUP LOG com-
mand with the NO_TRUNCATE option.

The transaction log cannot be backed up if any of the following conditions exist:

■ (^) The database uses a simple recovery model.
■ (^) The database uses a bulk-logged recovery model, a bulk-logged operation has been
executed, and the database fi les are damaged.
■ (^) Database fi les have been added or removed.
■ (^) The database uses bulk-logged or full recovery model, and a full database backup
has not been performed yet.
In any of these cases, perform a full database backup instead.
c21.indd 566c21.indd 566 7/31/2012 9:22:51 AM7/31/2012 9:22:51 AM
http://www.it-ebooks.info

Free download pdf