Sql-server – Does SQL Server re-create system databases if they are lost/missing

restoresql serversql-server-2012system-databases

We have a third-party server backup tool running every 24 hours, which backs up everything (files and database in preparation for a bare-metal restore). After much investigation, it emerged that the tool used non copy_only backups, thus destroying the log chain on both the system databases, and our own.

(I've been researching whether the system databases should be backed up, and the consensus is generally yes because of the data they hold concerning SQL Server in general (e.g. users, agent jobs, etc). This isn't so much about their contents, but what would happen if they were missing after a restore because of the situation I describe).

To stop this crime, I've disabled the tool performing database backups, so now it only does file backups (except the MDF/LDF files). I then have scheduled SQL Agent to run backups every hour and I then sent them to my private cloud.

In the event of complete server failure, and a bare metal backup was required, I expect that the databases wouldn't be there when SQL started back up, as they weren't backed up/restored by the tool (although I have them safely backed up).

What actually happens at this point? Does SQL Server re-create the system databases, which I then can restore over? Or, does it just refuse to start up and I'm heading for trouble?

Best Answer

Answering the initial question

No.

Providing a solution

The procedure of restoring the system databases is explained in the following Microsoft Article:

Reference: Rebuild System Databases (SQL Server 2012)

Prerequisites

  1. Ensure you have a clear documentation of the old system:
    • SQL Server Instance Configuration
    • Service Packs and Hotfixes
    • Current location of database files

Restore steps

  1. Rebuild the system databases:

    • Insert SQL Server 2012 installation media
    • Perform a rebuild using the following command:
      Setup /QUIET /ACTION=REBUILDDATABASE /INSTANCENAME=InstanceName /SQLSYSADMINACCOUNTS=accounts [ /SAPWD= StrongPassword ] [ /SQLCOLLATION=CollationName]
      Replace the relevant information with the values for your instance.
  2. Verify that the installation was successful by consulting the setup summary file:

    C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\Logs
    
  3. Restore the most recent backups of the system databases: master, msdb, (model):

    • When restoring the master database start the SQL Server instance from a DOS prompt with the -m parameter.
      Reference: Restore the master Database (Transact-SQL) for more details
    • When restoring the msdb database start the SQL Server instance with the Trace Flag 3608:

      Prevents SQL Server from automatically starting and recovering any database except the master database. Databases will be started and recovered when accessed. Some features, such as snapshot isolation and read committed snapshot, might not work. Use for Moving System Databases and Moving User Databases. Do not use during normal operation.

      Reference: Trace Flags (Transact-SQL)

  4. Rebuild the ressource database:

    • Launch SQL Server 2012 setup program from installation media
    • Click Maintenance and then Repair
    • Select your Instance
    • On the Ready to Repair summary page click Repair
  5. Restore your User databases

Please read

Important Notice
If you never perform a restore, you will never know if you backup (procedure) works. Test and test again.