You modify the SQL Server restore path with the WITH MOVE clause: match each logical file name in the backup to a new physical path using RESTORE FILELISTONLY to discover the names and RESTORE DATABASE ... WITH MOVE ... TO ... to place them. The key condition is that every data and log file must be listed, the target directories must already exist on the destination instance, and the SQL Server service account needs write access to them. For GUI users, SSMS exposes the same operation under Options > Files in the Restore Database dialog. The rest of this guide covers discovery, planning, execution, verification, and the failure modes that trip people up.
What "restore path" means and which layer you're changing
The phrase can mean three different things, and mixing them up causes avoidable errors.
The first is the physical file destination in the backup. A backup records the logical file names and their original physical paths. The WITH MOVE clause overrides where those files land. This is the layer most people mean, and it's what this article focuses on.
The second is the instance's default data and log directory, set in SQL Server Management Studio under server Properties > Database Settings. That default is what appears pre-filled when you restore through the GUI, but it doesn't override a backup's recorded paths by itself. Changing it affects where newly created databases go and what the GUI suggests for restores, not what a script without MOVE does.
The third is the SQL Server service's startup parameters, which point to the master and model system database files. Relocating those is a separate, riskier operation involving -d, -e, and -l switches and a service restart. Don't confuse it with user database restores.
If you're relocating a database to a new drive, a new server, or a new instance, you're in the first category. The mechanics are identical across SQL Server 2016 through 2022 and Azure SQL on a VM, with one notable version difference covered below.
Prerequisites before you touch a restore command
Gather these first. Skipping them is the usual reason a restore fails halfway through.
You need the backup file (.bak for full, .trn for log, .diff for differential) and its location readable by the SQL Server service account, not just by your Windows login. Files on a network share require the service account to have share and NTFS permissions; the SQL Server service itself does not use your mapped drives or your credentials.
You need the target directories created on the destination server. SQL Server creates the database files but does not create the folder structure, with limited exceptions in newer versions covered below. Create the folder tree in advance with the same or broader permissions than the service account.
You need to know your destination instance's edition and version. Restoring a backup taken on a newer major version to an older one is not supported. Restoring between editions follows licensing rules you should confirm against Microsoft documentation for your specific editions.
You need sysadmin or dbcreator rights on the destination instance, plus the RESTORE permission, and permission to view the file list.
Finally, confirm no database on the target already uses the name you're restoring. You can restore over an existing database with WITH REPLACE, but do that deliberately, not by accident.
Step 1: Read the logical file names and sizes inside the backup
The critical discovery step. Run this against the backup before you plan any paths:
The result set includes one row per file. The columns that matter are LogicalName, PhysicalName, Type (D for data files, L for log), FileGroupName, and Size. A simple database with one data file and one log file gives two rows; a database with multiple filegroups, filestream containers, or memory-optimized filegroups gives more.
Record every logical name exactly. You'll paste these into the MOVE clauses. A typo produces the error "Logical file name ... was not found in the backup," and the restore aborts cleanly before writing anything, which is a safe failure but a wasted attempt.
Note the size of each file, too. Sum the data file sizes and add the log, then check free space on the target volume. Growth settings matter as well: a database that grows quickly needs headroom, not a tight fit. Also note the PhysicalName values themselves; they tell you the original platform's conventions (drive letters, mount points, or Linux-style paths if the backup originated on SQL Server on Linux).
If you want the backup's metadata too, RESTORE HEADERONLY returns the database name, backup type, server version, and backup date, useful for confirming you have the right file and that the versions are compatible.
Step 2: Plan the destination paths and permissions
Choose a target directory for data and another for logs when your environment separates them. Keeping data files on one volume and log files on another is a common layout for performance, but the restore doesn't require it; the requirement is that the paths exist and are writable.
The service account needs Modify permission on the destination folders, or at minimum create-files and write-data rights. The account name depends on how SQL Server was installed. Default standalone installations in recent versions typically run as a virtual account whose effective permission comes from the machine's administrators group or specifically from the folder's ACL granting that service. Named instances and domain-configured deployments vary, so check the actual service account under the service's properties or SELECT servicename, service_account FROM sys.dm_server_services;.
A quick way to check the effective account is to create a test file from the service account. Without an interactive login, the practical alternative is to verify the ACL explicitly and then test the restore on a small database before committing to the production one.
Decide whether you'll build paths by hand or generate the command. For databases with many files, generate the MOVE clauses from the FILELISTONLY output rather than typing:
That's illustrative scaffolding; verify the generated lines and adjust directory names before pasting them into a real restore. It works for well-named logical files and breaks on names containing apostrophes or spaces that need escaping, so inspect the output.
Step 3: Run the restore with WITH MOVE
Here's a complete restore preserving the existing database name and relocating every file:
The MOVE clause pairs each logical name (single quotes) with the new physical path and file name (also single quotes). RECOVERY brings the database online after the restore. STATS = 10 prints progress every 10 percent, which is reassuring on large backups and helps you spot a stall.
To restore under a different database name while pointing at the same files, change the first argument to the new name and air on the side of distinct file names to avoid confusion:
If the target database already exists and you're intentionally overwriting it, add REPLACE. If you're restoring to a point in time or recovering from a sequence of backups, use NORECOVERY on intermediate restores and RECOVERY (or STANDBY) on the final one. Log restores also use MOVE when the log file's physical path differs from what the backup records, though if you're keeping the same layout as the source, you can omit it.
Watch for these outcomes. A successful restore reports "RESTORE DATABASE successfully processed ... pages" and the database appears in sys.databases with state ONLINE. A permissions failure surfaces as operating system error 5 (access denied) during the file creation phase. A missing directory surfaces as operating system error 3 (the system cannot find the path specified). An invalid logical name surfaces as the "not found in the backup" error before any write occurs.
Step 4: Verify the files landed where you intended
Don't assume. Query the catalog:
Confirm every data and log file points to the new path. Then run a quick integrity and sanity pass:
CHECKDB on a very large database can be expensive; in a tight maintenance window, at least confirm the database is online, the file sizes match expectations, and a representative query returns. The catalog query is the authoritative check that the move actually happened rather than the files landing alongside the originals on a volume that happened to have space.
The Management Studio route, and where it diverges
The Restore Database dialog in SSMS works for the common case. Select Device, point at the backup, and on the Files page, the "Restore As" column shows each file's target physical path, editable inline. That's the GUI equivalent of MOVE.
The divergence worth knowing: on the Files page, SSMS pre-fills paths based on the instance's default data and log directories, not automatically on the backup's recorded paths, which is convenient when you're restoring to a fresh server. However, the generated script reflects whatever you accepted, so review the Script button's output before executing on production. That script is what actually runs, and it makes the MOVE clauses explicit.
A version-specific wrinkle: SQL Server 2022 introduced RESTORE ... WITH MOVE behavior improvements and options such as restoring with a new path via WITH MOVE combined with automatic directory creation in some configurations, and Azure SQL Managed Instance supports limited file movement through T-SQL only for certain scenarios. The reliable rule remains: create the directory yourself and keep the script explicit. Don't depend on automatic directory creation across versions you haven't verified.
Common failures and how to read them
The restore fails with "Cannot open backup device." Either the path is wrong from the service's perspective or the service account lacks read access. The fix is permissions or a local copy of the backup; the service doesn't see your user's mapped drives, including drive letters mapped in your session but not in the service's session.
The restore fails with "The file ... is not a valid Microsoft Tape Format backup set" or similar. You may be pointing at a file that isn't a backup, an incomplete copy, or a backup from an incompatible version. RESTORE HEADERONLY will usually confirm or refute version compatibility.
The restore aborts with "The media set has 2 media families but only 1 are provided." You have a striped backup set; you need all the files. Point at all of them with multiple DISK = clauses.
The restore fails with "Exclusive access could not be obtained because the database is in use." The target database is open and someone is connected. Take it offline or use WITH REPLACE plus force-close connections, understanding the impact. For a fresh restore under a new name, this error usually signals a name collision.
The restore reports success but the files sit in the old location. You probably ran the restore without MOVE and the original paths existed on the target. The catalog query from Step 4 catches this every time.
You hit operating system error 5 when the directory exists but the new file name does. SQL Server won't overwrite existing database files unless the restore is replacing that database, and even then leftover files from a failed attempt can block progress. Confirm no stale files occupy the intended names before retrying.
The one case where I'd stop and involve a DBA or infrastructure owner is relocating system databases (master, msdb, model) or moving files across a clustered instance's shared storage. Those operations involve service restarts, cluster resource dependencies, and a wrong step leaves the instance unable to start. User database restores with MOVE don't reach that level of risk, but system database moves do.
Moving files after a restore instead of during it
Sometimes the easier path is to restore in place and then detach and reattach:
This changes the catalog's recorded path but does not move bytes on disk. Copy the offline files to the new locations with Windows Explorer or robocopy while the database is offline, then bring it online. The order matters: modify the catalog, take the database offline, copy the files, then online. Getting the order wrong brings the database online looking for files that haven't moved.
That route is useful for relocating an existing database without a backup, or when a failed MOVE restore left files in the wrong place. It's more steps than a fresh WITH MOVE restore and carries more window time, so for a planned relocation from backup, WITH MOVE is the cleaner choice. For a database that's already online and you just want it on a new drive, MODIFY FILE with an offline copy is the standard approach.
A worked estimate: planning disk space
Suppose FILELISTONLY shows one data file of 80 GB and a log file of 20 GB. You need at least 100 GB free on the target paths, but a restore rebuilds those files at roughly their recorded sizes, so add 10 to 20 percent headroom for growth and for any indexed or filestream content that isn't captured in the raw sizes. If you're keeping the source online during the restore, the two copies coexist, so account for both. The arithmetic is straightforward; the failure is usually planning for the database's current size rather than its size plus growth. Log files in full recovery model continue to grow until the next log backup, so if you're relocating to a small volume, check the log's growth settings in the source database and consider shrinking or reconfiguring before the move.
For striped backups across multiple files, the restore reads all of them, and you need all the media families available simultaneously. Restoring from a network share where one of several backup files is missing produces a partial-media error rather than a partial restore, which is the safe behavior.
Relocating log files after restore in an availability group
One edge case in Always On Availability Groups deserves a mention. Restoring a database that will be added to an availability group requires WITH NORECOVERY on the primary replica, and the secondary replicas maintain their own file paths. You can specify different physical paths per replica using the MOVE clauses in the RESTORE command executed on each replica, or use the path configuration in the Add Database wizard. For a restore to the primary, the primary's path mapping applies; secondaries get their local paths through their own restore operations. This is why "restore path" in an AG context means per-replica configuration, not one global setting. Confirm the target paths exist on every replica before initiating, or the secondaries fail their local restores while the primary succeeds, which is a confusing partial state to debug.
Choosing between scripts, GUI, and generated T-SQL
Scripted restores with explicit MOVE clauses win on repeatability and reviewability. They live in source control, they show exactly which logical name maps to which path, and they survive an SSMS version change. The GUI is faster for one-off restores to a fresh server and for browsing what's in the backup.
My recommendation: use FILELISTONLY and a generated script for anything you'll run more than once, and use the GUI's Files page for exploratory restores you'll discard. If you're scripting at scale, parameterize the restore script or wrap it in PowerShell's Restore-SqlDatabase with -RelocateFile objects; the underlying behavior is the same MOVE operation, and the wrapper improves repeatability without hiding the mapping.
The one practice worth adopting regardless of tool: always query sys.master_files after the restore. The restore command editing the catalog is the goal, and that query is the ground truth that it happened.