Cannot Open Backup Device: Operating System Error 5 (Access Is Denied)

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.Related pillar: Backup & Recovery

Msg 3201 with OS error 5 means SQL Server cannot write the backup file. Check its service account, then verify that account has access to the share and NTFS folder.

What Error 3201 Says

Msg 3201  ·  Level 16  ·  State 1
Cannot open backup device 'D:\Backups\SQL\RestoredSales.bak'. Operating system error 5(Access is denied.). BACKUP DATABASE is terminating abnormally.
⚡Find the real identity first: sys.dm_server_services shows the account SQL Server writes as. Grant it Modify on both the share and the NTFS folder; changing your own permissions does not help.
SSMS Messages tab showing Msg 3201, cannot open backup device, operating system error 5 access is denied, followed by Msg 3013 BACKUP DATABASE is terminating abnormally

Find the Service Account SQL Server Uses

SQL Server writes backups as the Database Engine service account, not as the person who ran the command. Your own access to that folder is irrelevant. Microsoft documents the service accounts and their Windows permissions.

Find out who is actually being refused:

SELECT  servicename,
        service_account,
        startup_type_desc,
        status_desc
FROM    sys.dm_server_services;

That service_account is the identity that needs permission on the backup path.

A virtual account cannot reach a network share. NT SERVICE\MSSQLSERVER and NT AUTHORITY\SYSTEM present as the machine account when they leave the box, so if you are backing up to \\fileserver\backups, permission has to be granted to DOMAIN\SERVERNAME$, not to a user. That single fact accounts for a large share of these errors.


Tell a Permission Error from a Path Error

Operating system error 5 says access denied, but the same Msg 3201 appears with other OS errors that mean completely different things:

OS errorMeansUsually
5Access is deniedService account has no rights on the path
2Cannot find the file specifiedThe folder does not exist, or a typo
3Cannot find the path specifiedA drive letter or share the server cannot see
32The process cannot access the file, it is in useAntivirus, or a previous run still holding it
112Not enough space on the diskExactly what it says
1326Logon failure, bad username or passwordA stored share credential has expired

Read the number before assuming permissions. OS error 2 on a path you can see in Explorer nearly always means a mapped drive, which is covered below.


Check Whether SQL Server Can See the Path

Operating system error 5 and operating system error 3 arrive as the same Msg 3201 and need opposite fixes, so the first job is telling them apart. 2 backups of 1 database to 2 paths on SQL Server 2025 CU8: the first folder exists and the service account is denied write on it, the second folder is not there at all.

Two backup failures and the checks that distinguish themCaptured on SQL Server 2025 CU8. Read the output; do not rerun it.
Changed database context to 'master'. -- Attempt 1: a folder the service account cannot write to Msg 3201, Level 16, State 1, Server HPAI01, Line 1 Cannot open backup device 'D:\Backups\SQL\RestoredSales.bak'. Operating system error 5(Access is denied.). Msg 3013, Level 16, State 1, Server HPAI01, Line 1 BACKUP DATABASE is terminating abnormally. -- Attempt 2: a folder that is not there Msg 3201, Level 16, State 1, Server HPAI01, Line 1 Cannot open backup device 'D:\Backups\Archive\RestoredSales.bak'. Operating system error 3(The system cannot find the path specified.). Msg 3013, Level 16, State 1, Server HPAI01, Line 1 BACKUP DATABASE is terminating abnormally. -- Who is actually being refused servicename|service_account|status_desc -----------|---------------|----------- SQL Server (MSSQLSERVER)|NT Service\MSSQLSERVER|Running -- Can SQL Server see each path at all path|file_exists|file_is_a_directory|parent_directory_exists ----|-----------|-------------------|----------------------- D:\Backups\SQL|0|1|1 path|file_exists|file_is_a_directory|parent_directory_exists ----|-----------|-------------------|----------------------- D:\Backups\Archive|0|0|1

sys.dm_os_file_exists is the discriminator, and it answers as the service account rather than as you. file_is_a_directory of 1 on the denied folder says SQL Server can see that folder perfectly well, so error 5 is about rights on a path it has already found. file_is_a_directory of 0 with parent_directory_exists of 1 on the second says the folder is simply missing, and no permission change will help. xp_fileexist returned the identical 3 values for both paths, so use whichever you prefer. Neither needs xp_cmdshell.

Msg 3013 follows both failures and is noise. The 3201 line carries the only 2 facts that matter, the path SQL Server actually tried and the operating system error number it got back.


Fix the Backup Destination

Local Path

Grant the service account Modify on the folder, not just Read. A backup writes, and it also has to create the file.

icacls "D:\Backups" /grant "NT SERVICE\MSSQLSERVER":(OI)(CI)M

Use the account sys.dm_server_services reported, not a guess.

Network Share

Two sets of permissions have to agree, and people usually fix only one:

  • Share permissions, on the share itself
  • NTFS permissions, on the underlying folder

Grant both to the machine account if SQL Server runs under a virtual account (DOMAIN\SQLSERVER01$, note the dollar sign), or to the domain service account if it uses one.

Test it as SQL Server rather than as yourself:

-- Does SQL Server itself think it can see the path?
EXEC master.dbo.xp_fileexist '\\fileserver\backups\test.txt';

A Parent directory exists of 0 means SQL Server cannot see the folder at all, which is a permissions or path problem rather than anything to do with the backup command.

A Mapped Drive That Only You Can See

BACKUP DATABASE [YourDb] TO DISK = N'Z:\Backups\YourDb.bak';

Mapped drives are per user session and SQL Server will not have yours. Z: exists for you and does not exist for the service. This gives OS error 2 or 3 rather than 5, which is the giveaway.

Always use the UNC path, never a drive letter:

BACKUP DATABASE [YourDb] TO DISK = N'\\fileserver\backups\YourDb.bak';

It Worked Yesterday and Fails Today

Three things change underneath a working backup job:

  • The service account password changed, or the account was locked, so it can no longer authenticate to the share
  • Antivirus started scanning the backup folder. This shows as OS error 32, and backup folders should be excluded from real-time scanning anyway
  • The share was recreated, which resets share-level permissions even when NTFS permissions survive

Prevent the Next Backup Failure

✓

Exclude backup folders from antivirus. It causes intermittent failures that are miserable to diagnose precisely because they only happen sometimes.

✓

Use UNC paths in every backup job, so nothing depends on a drive mapping that exists in one session.

✓

Grant to a group, not to the account. When the service account changes you change one group membership rather than hunting every folder.

✓

Alert on backup age, not on job failure. A job that fails and is retried by hand still leaves a gap if nobody notices.


Frequently Asked Questions

The path works when I test it, so why does the backup fail?
Because the backup does not run as you. SQL Server writes as its service account, so your own access to the folder proves nothing. sys.dm_server_services tells you which account is actually being refused.
Why can I not back up to a mapped drive?
Mapped drives belong to a user session and SQL Server does not have yours. The drive letter does not exist for the service, which is why you get operating system error 2 or 3 rather than 5. Always use the UNC path.
It worked yesterday and fails today.
Three usual culprits: the service account password changed or the account locked, antivirus started scanning the backup folder (operating system error 32), or the share was recreated, which resets share permissions even when NTFS permissions survive.
Does a RESTORE throw this too, or is it only backups?
Both, and the state number tells you which side you are on. Reproduced against a path that does not exist: a BACKUP returns Msg 3201, Level 16, State 1 and a RESTORE HEADERONLY returns Msg 3201, Level 16, State 2, each followed by Msg 3013 saying the operation is terminating abnormally. The 3013 is noise, the 3201 is the error. The difference that matters operationally is the permission being tested: on backup the service account needs to write to that folder, on restore it needs to read the file. A share that a backup job can write to is not automatically one a restore can read from, which is why restores fail on paths that have been backing up happily for months.

Where To Go Next

If the service account can write to the backup path, use these next for the other backup failures and checks:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *