datablogs

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

Environment : 

We are trying to migrate on premises to AWS RDS , In this case due to disk adding issue on onpremises we have added big disk on the AWS EC2 server and shared with outside 

While trying to take a backup from SQL Server to a remote shared folder like:

\\xxx\SQLBackups\test1.bak

we encountered the common error:

Cannot open backup device '\\xxx\SQLBackups\test1.bak'.Operating system error 5

(Access is denied.)

Root Cause

The issue usually happens because of permissions.

In our case :

  • SQL Server was running under: NT Service\MSSQLSERVER
  • This is a local virtual account
  • It does not have access to network shares

So even if the shared folder is accessible manually, SQL Server cannot write to it.

Other Methods We Tried (And Why They Failed)

MethodIssue
Native Full/Diff/Log BackupNT Service\MSSQLSERVER cannot access shared/S3/remote drives
DACPACOnly metadata export, not usable for full restore in RDS
BACPACBackup works, but restore fails (compatibility issues)
Log ShippingRequires manual setup + S3 upload + folder access problems
S3 URL BackupSupported only from SQL Server 2022
AWS DMSRequires CDC + replication setup (complex overhead)

Quick Workaround That Worked

We used xp_cmdshell to authenticate the network share:

-- Enable advanced options
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;

-- Enable xp_cmdshell
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;

-- Authenticate network share
EXEC xp_cmdshell 'net use \\xxx\SQLBackups /user:Administrator xxxxxx';

-- Take backup to network share
BACKUP DATABASE [YourDatabase]
TO DISK = '\\xxx\SQLBackups\test1.bak'
WITH FORMAT, COMPRESSION, STATS = 10;

This creates a session with proper credentials, and the backup started working.


0 Comments