You restore SQL Server's master database by starting the instance with the -c -f -m startup parameters (single-user mode, minimal configuration, no published service change), then issuing RESTORE DATABASE master FROM DISK = '...' WITH REPLACE; from a sqlcmd session on the local machine. The condition that decides everything: the restored master must come from the same SQL Server build and mostly the same server, because a successful copy that doesn't match the binary's system catalog can leave the instance unstartable or silently wrong.

That framing hides most of the work. Restoring master is unlike restoring a user database. SQL Server cannot run a normal restore of the database that defines its logins, linked servers, and system metadata while it's live; you have to put the instance into a degraded-but-responsive state first, and then deal with every piece of state that master didn't carry. What follows walks through preparation, the rebuild, the restore, the verification, and the recovery of everything master doesn't protect.

What the master database actually contains, and why that matters before you start

Master stores instance-wide metadata: the list of databases and their file locations, login accounts and their SIDs, linked server definitions, endpoint configuration, server-level configuration options, the SQL Server service master key references, and the location of the resource database. It does not store user objects, job definitions (in most deployments those live in msdb), or the contents of your user databases.

That division is the whole reason a master restore needs a manual pass afterward. Restoring an older master rolls the server's view of reality back to the backup's timestamp. Databases created after that backup lose their catalog entries and appear as suspect or missing, even though their MDF and LDF files still sit on disk. Logins created after the backup vanish, which orphans database users mapped to those logins. Linked servers and configuration changes made after the backup disappear. You re-apply all of that by hand or via script after the instance is healthy again.

Two boundaries frame the job. First, a restore of master from a backup must use a backup taken from the same instance and SQL Server version and edition; Microsoft's documentation is explicit that you restore master only from a matching build. Restoring master from a different service pack, cumulative update, or major version is unsupported and may fail or corrupt system catalog assumptions. Second, if master itself is damaged or the backup is unusable, the fallback is not a restore at all — it's a rebuild, covered below.

Prerequisites: what you need before touching anything

Before you stop the service, assemble the following. Skipping this list is the most common cause of a stalled recovery.

A verified master backup. Confirm it exists and is readable. The default automated backup-maintenance jobs many shops configure do not always include master; check msdb.dbo.backupset history or wherever your backup catalog lives. Note the backup's timestamp, because you will compare it against live state later. The SQL Server build number of the currently installed instance. Run SELECT @@VERSION; if the instance is still responsive, or read it from error logs and the Setup bootstrap logs if it isn't. You need this to confirm the backup originated from the same build. Local administrator rights on the host and the ability to stop and start the SQL Server service (Windows service name typically MSSQLSERVER for the default instance, MSSQL$InstanceName for a named one). A sqlcmd client on the host, plus -E trusted-connection access. In single-user mode the local administrators group generally can connect; confirm your account's group membership. A documented inventory of post-backup state: databases created since the backup, logins added, linked servers, server configuration changes, and any encryption keys or certificates. You can pull this from memory, from monitoring, from application teams, or from a still-running instance before you take it down. Do not assume you'll remember it under pressure. Copies of the master backup and, critically, the [m]ssql system databases actually needed. Material master, msdb, and model are the standard trio to back up together; a master-only restore means you must also make msdb and model consistent with it. Plan for that. Any server-level encryption material: the service master key backup, and any database master keys, certificates, and asymmetric keys you need to decrypt objects. These are not in master's backup in usable plaintext form.

One more check before downtime: if the instance is still running, save SELECT name, sid FROM sys.server_principals;, SELECT * FROM sys.databases;, and SELECT name, value_in_use FROM sys.configurations; to a file. That snapshot is your post-restore reconciliation checklist.

Two paths exist, and you must pick correctly

A restore assumes a usable master backup exists. A rebuild assumes it doesn't, or assumes the backup is so stale that restoring then reconciling is riskier than rebuilding from the known-good installed template. In practice, the safest decision rule is:

If a master backup exists from the same build and recent enough that you can reapply the deltas, restore. If no valid backup exists, or the instance's binary is damaged, or the restore repeatedly fails, rebuild from setup media and then restore the user databases.

Rebuild is also the recovery step after a failed restore, so the two paths sometimes meet. The rebuild procedure below is the more destructive one: it replaces master (and optionally other system databases) with fresh copies from the installation media, then you reattach or restore user databases afterward. It requires the SQL Server installation media or the setup bootstrap folder, which is retained on the host under C:\Program Files\Microsoft SQL Server<version>\Setup Bootstrap\ in normal installs.

Path A: Rebuild master from installation media (when no usable backup exists)

A rebuild creates a new master from the template on the setup media. Everything instance-specific that lived in master is reset: logins, linked servers, most configuration, database registrations. You are effectively rebuilding the "house" around the still-present user database files. The keys are correct parameters, proper ordering, and reattaching, not restoring, user databases.

Before you start, take the SQL Server service out of any cluster or Always On role where it can fail over mid-rebuild; performing a rebuild on a node in an availability group requires removing it from the group first and is a broader operation than this guide covers. For a standalone instance, back up the user database files' locations and note them, then plan the maintenance window.

1: Stop the SQL Server service. In an elevated command prompt: net stop MSSQLSERVER (or the named-instance equivalent). Also stop SQL Server Agent if it's running (net stop SQLSERVERAGENT), so it doesn't attempt reconnects mid-rebuild. 2: Run setup from a command prompt with rebuild parameters. Locate setup.exe in the installation media or the Setup Bootstrap folder and invoke it with the parameters that trigger a system-database rebuild — in the common case, something like setup.exe /q /ACTION=RebuildDatabase /INSTANCENAME=MSSQLSERVER /SQLSYSADMINACCOUNTS="BUILTIN\Administrators" /SAPWD="". /q runs it silently; omit it to watch progress in the GUI. The /SQLSYSADMINACCOUNTS value grants sysadmin to the account(s) you specify, using domain-qualified Windows groups rather than individual accounts where your security model allows; /SAPWD sets the new sa password. Exact parameter support varies by SQL Server version, and setup validates them before it touches anything — read the resulting Summary.txt under the Setup Bootstrap logs before proceeding to the next step if setup flags anything. 3: Wait for the rebuild to complete and confirm in the log. Setup reports failure through exit code and log entries. Do not interpret "service restarted" as success; check the Summary log and the service start state together. 4: Start the service and connect. net start MSSQLSERVER, then sqlcmd -S . -E -Q "SELECT @@VERSION;". The instance now has a fresh master with Windows built-in groups granted sysadmin as you specified; the sa account is either disabled or has the password you provided. 5: Recreate logins, then reattach user databases. Because master no longer knows about them, use CREATE LOGIN for each login inventory you saved, then use sp_attach_db or CREATE DATABASE ... FOR ATTACH for each user database. Prefer attach over restore here; the data files are intact and attach is faster. If your user databases were NOT in a usable state, restore them from their own backups instead. 6: Restore msdb and model. Rebuilding master alone leaves msdb and model from the old binary if you used the default rebuild, which is inconsistent with a fresh master. Attach or restore msdb from its backup after the user databases, and ensure model matches the build. If you care about jobs, backup history, and maintenance plans, restoring msdb from backup is the standard route.

The check for success in Path A: SELECT COUNT(*) FROM sys.databases; should list your system databases plus the reattached user databases, and each user database should be ONLINE with a non-empty sys.databases.state_desc. If any shows SUSPECT, compare the file paths recorded in the pre-rebuild inventory to sys.master_files.

Path B: Restore master from a matching backup (single-user mode)

This is the path the question's phrasing targets, and it is the more delicate one because you are overwriting master rather than regenerating it. The -c -f -m startup parameters let the instance start enough to accept a connection but not enough to be a fully functional server: -f starts in minimal configuration (so a broken setting in the restored master can't block the start), -c bypasses the service control manager's normal startup so the start isn't tied to a service, and -m limits connections to one. The combination you need is a single-user, minimal-config start.

1: Stop SQL Server and SQL Server Agent. net stop MSSQLSERVER, net stop SQLSERVERAGENT. Confirm with sc query MSSQLSERVER that the service is STOPPED before editing anything. 2: Add the startup parameters to the instance. In SQL Server Configuration Manager, right-click the instance, choose Properties, open the Startup Parameters tab, add -c, -f, and -m as separate parameters, click Apply, then Start the service. Alternatively, start the service binary manually with those flags from an elevated command prompt if configuration-manager changes aren't permitted. Record exactly what you added so you can remove it immediately afterward — leaving -m in place makes every future start single-user. 3: Connect using sqlcmd from the local machine as a local admin. sqlcmd -S . -E (or -S localhost -E). Do not use SSMS for the restore step if the instance is in single-user mode and you're uncertain how it will hold the single connection; sqlcmd gives you explicit control. If the connection is refused, close any open object explorer sessions — those count against the single-user limit. 4: Restore master with REPLACE. Run:

RESTORE DATABASE master FROM DISK = 'D:\Backups\master_full.bak' WITH REPLACE, RECOVERY;

REPLACE is required because master is a system database. RECOVERY returns the database to a usable state. Do not add WITH NORECOVERY — that produces a restoring master, and the next server start can fail. If the backup is a copy of a master from a different build, stop: the restore may accept but the instance will misbehave, and it is explicitly unsupported. 5: Immediately shut down the instance after the restore reports success. When sqlcmd returns "RESTORE DATABASE successfully processed," the master file has been replaced, but the server is still running its in-memory configuration from the old master. Shut it down cleanly with SHUTDOWN WITH NOWAIT; from the sqlcmd session, or net stop immediately after the command exits. Do not start it yet. 6: Remove the -c -f -m startup parameters. Go back to Configuration Manager (or the binary invocation) and delete the three parameters you added. This is mandatory; if you skip it, the server boots single-user every time and you'll have to redo this under pressure. 7: Start the service normally and reconnect. net start MSSQLSERVER, then sqlcmd -S . -E -Q "SELECT name, state_desc FROM sys.databases;". 8: Run the verification in the next section. The instance may start cleanly and still be in a reconciled-but-incomplete state; the check is where the real success is measured.

A success check for the restore itself: the RESTORE line reports the backup file set and finish time, and the difference between that backup's timestamp and your inventory is the window you must reconcile. A failure check: if the restore returns an error about incompatible media or a version mismatch, do not retry with the same file — that's your cue to switch to Path A.

How to check that the restore actually took

A clean startup is necessary but far from sufficient. Four checks, in order from cheap to expensive, tell you whether the instance is healthy.

First, system database status. Run SELECT name, state_desc, recovery_model_desc FROM sys.databases ORDER BY name;. master, model, msdb, and tempdb should all be ONLINE. tempdb always reinitializes on startup, so it's expected to be empty, but if tempdb is OFFLINE or RECOVERY_PENDING, the disk or permissions changed and that's your signal to stop.

Second, login and user mapping. Run:

SELECT p.name AS login, p.type_desc, s.name AS mapped_db FROM sys.server_principals p LEFT JOIN sys.database_principals ... — more simply, use the sys.login_token and sp_helplogins checks, or directly query SELECT name FROM sys.server_principals WHERE type IN ('S','U') ORDER BY name;. Compare to your saved inventory. Any SQL login that was created after the backup is gone and every user mapping to it is now orphaned. Fix orphaned users with ALTER USER [user] WITH LOGIN = [login]; per database, after creating the login in master.

Third, database inventory. SELECT name, state_desc FROM sys.databases; should match your saved list. Databases created after the backup have no metadata in master and their files are unattached; databases dropped since the backup reappear as registrations with no files. Expect both and reconcile deliberately.

Fourth, server configuration and linked servers. SELECT name, value_in_use FROM sys.configurations ORDER BY name; and SELECT * FROM sys.servers;. Any configuration change made after the backup is rolled back; on a server with memory, maxdegree, or backup settings tuned in a post-backup window, this can affect performance or backup behavior. Reapply deliberately rather than reflexively.

A sequencing subtlety: if you restored master but not msdb, the instance may operate but SQL Server Agent jobs, backup history, and some maintenance features will be inconsistent with the "new" master. The standard practice is to restore msdb from a backup near in time to the master backup, then reconcile from there. If msdb is unrecoverable, the rebuild path (Path A) with re-attachment is often the cleaner route.

Reconciling what master's backup didn't include

The restore brings the instance back to the backup's moment in time. Everything after that moment is your recovery work, and it is best done in a fixed order so later steps build on earlier ones.

Start with logins. Recreate each missing login with the same SID where you can — capture the SID from your inventory or from the user database with SELECT DISTINCT SID FROM sys.database_principals WHERE SID IN (SELECT SID FROM sys.server_principals); — and use CREATE LOGIN ... WITH SID = 0x... so remapping is unnecessary. Windows-group logins usually resolve themselves through AD membership; use ALTER LOGIN ... FROM WINDOWS where authentication is Windows-based. Re-grant fixed server roles and explicit grants from your inventory.

Then databases and file locations. For user databases created after the backup, prefer CREATE DATABASE ... FOR ATTACH after confirming the files intact, or their own restores if you had separate backups. For databases that should exist but whose catalog entries were rolled back, verify file paths against sys.master_files and use sp_attach_db only when the files are the last saved state and nothing since has changed them.

Then server configuration. Reapply the values from your saved snapshot. Notice what else moved: the default backup directory, database mail settings, and trace flags. These are individually small but collectively explain "the server behaves differently after the restore" reports.

Then linked servers, endpoints, and service broker configuration that lived in master. Linked server logins are notoriously tricky; the local login mappings need to be rebuilt even when the linked server definition survives.

Finally, encryption material. The service master key is regenerated or restored; if you have a backup of it, restore with RESTORE SERVICE MASTER KEY FROM FILE = '...' DECRYPTION BY PASSWORD = '...'; and then ALTER SERVICE MASTER KEY FORCE REGENERATE; only where necessary and after reading the consequences — force regeneration unwraps existing secrets that can't be recovered without the old key. Database master keys, certificates, and asymmetric keys generally need to be restored within each database that uses them and re-associated with CREATE CERTIFICATE ... FROM FILE. Schema-bound encryption is not something to improvise mid-incident; if encrypted objects exist, plan this step in a maintenance window after the instance is otherwise healthy.

If, after all of this, logins still resolve but the application fails on permission, look for orphaned users whose SID has no match and use ALTER USER rather than a brute-force sp_change_users_login call — the former is precise and reversible; the latter's semantics have changed across SQL Server versions.

Common failure modes that turn a restore into a crisis

The following are the failures that most often convert a routine restore into an outage, roughly in order of frequency.

Restoring a backup from a different build. The restore may succeed, then the instance fails on startup or behaves strangely under load because master's catalog schema doesn't match the executable's expectations. The fix is the rebuild path, not retries. Confirm build equality with SELECT @@VERSION before you begin.

Forgetting the REPLACE clause returns error 3101-like messages about the master database; adding the clause is correct, but confirm you're restoring master and not accidentally naming another database.

Leaving -m in place after the restore. Every restart single-user, and applications can't connect. Remove the parameters before starting. This is the most common post-success mistake because people stop at the restore's success message.

Not having a master backup at all. This is the case that the maintenance-plan mindset should prevent; master is small and benefits from frequent, automated full backups distinct from the user-database schedule. If it happens, the rebuild is your route and reattachment of every user database your job.

Restoring a stale master without a reconciliation plan. The backup is valid but months old; the instance comes back "fine" but lacks every login, linked server, and database created since. Recover, then reconstruct from the inventory; if the gap is too large, decide between the restore-plus-reconcile path and a full rebuild with an explicit system state export.

Ignoring msdb. Jobs and maintenance plans are commonly thought of as separately managed, but when msdb and master disagree about history and principals, SQL Server Agent can fail to start or jobs can be recreated against wrong owners. Restore msdb from a backup close in time, or rebuild it.

Reducing the next restore's cost: backup discipline and a recovery runbook

Three practices make this a scheduled exercise rather than a scramble.

Back up master on a distinct schedule even on servers where user-database backups are already frequent, and store the backup with a timestamp in its filename alongside the build number (master_full_15.0.4415.20261105.bak). Include the version check as part of the restore procedure rather than an afterthought; it prevents the build-mismatch failure outright.

Keep a server-state export script maintained next to the backup: a small T-SQL script that emits logins, linked servers, configuration, database inventory, and endpoints to a file. Run it on a schedule or at least after each significant change, so you can rebuild the deltas from a timestamp instead of from memory. This turns the reconciliation step from "reconstruct the business" to "diff two files."

Finally, test the restore and the rebuild once a year on a non-production copy. If the instance is large, test with a subset of it — the system database and user database names and paths must be preserved for the restore of master, but the user data can be substituted with placeholder files for the rebuild test. That exercise is also where you confirm the setup bootstrap path is present and your sqlcmd connection method works when the service policy has changed since the last test. A restore that only works on paper isn't a restore plan.