Restore master database from a current backup
Master database records important information of
whole SQL Server system. So you need to know some important things below
before you restore the database :
- If there have been any changes to master after the database backup was created, those changes are lost when the backup is restored. Therefore, it is necessary to re-create those changes manually after restoring master from a backup by executing the statements necessary to re-create the missing changes. For example, if any
logins have been created after the backup was performed, those are lost when master is restored. Re-create the logins using SQL Server Enterprise Manager or the original scripts used to create the logins.
Note : Any database users previously associated with logins that need to be re-created are orphaned because the login is lost. To associate an existing database user to a new SQL Server login,
please use sp_addlogin in Query Analyzer or Management Studio. To associate an existing database user with a Windows system user,
please use sp_grantlogin .
- If any user databases have been created after master was backed up, those databases cannot be accessed
unless the databases are reattached to SQL Server or the databases are restored from
backups.
Attaching the database to SQL Server re-creates the system table entries needed and makes the database available in the same state it was before the master database was restored. It is not necessary to re-create the database first; the files can be attached without knowing how the database was created, as long as all the files comprising the database are
attached.
It is necessary to restore a backup of the database only if the data and transaction log files of the database no longer exist or are unusable or damaged in some other way due to a media
failure.
If any databases are restored or attached after master is rebuilt, it is necessary to specify the same sort order, code page, and Unicode collation when rebuilding master as used by those databases. If the same sort order, code page, and Unicode collation are not used, it will not be possible to restore or attach those
databases.
If any objects, logins, or databases, for example, have been deleted after master was backed up, those objects, logins, and databases should be deleted from master.
Important : If any databases no longer exist, but are referenced in a backup of master that is restored, SQL Server may report errors when it starts because it cannot find those databases any longer. Those databases should be dropped after the backup is restored.
To restore master database :
- SQL Server needs to be started in single-user mode to prevent any additional users from using SQL Server. All SQL Server services (except SQL Server itself) and utilities, such as the SQL Server Agent, can be stopped because they may try to access SQL Server.
Different
edition of SQL Server has different way to start in single-user mode , for
2000 edition ,you can start it from a command prompt, enter
following command to start it in single-user mode independently of the Service Control Manager:
For default instance : sqlservr.exe -m
For named instance :
sqlserver.exe -sInstanceName -m
(e.g. sqlserver.exe -sMyInstance -m)
- Configure a restoration job for master
backups. then do the restoration.
- Restart the SQL Server service in multi-user
mode in Control Panel's Service Control Manager.
- When master has been restored and any changes have been reapplied, back up master immediately