sql-serverwindowsnetwork-programming

Invalid drive specification using XCOPY in a scheduled job in SQL Server


I use SQL Server 2014 on a Windows 2012r2 machine, and I need to copy backup files to another server (2012r2). I read this SO post:

Invalid drive specification using XCOPY

I was able to run the following successfully

net use Z: \\SQL02\H$

xcopy F:\BackupTest\*.bak Z:\BackupTest\ /s /d

However, I got the "Invalid drive specification" when using the same xcopy code in a scheduled job in the SQL Server database.


Solution

  • There's no need to map a drive. XCopy can use the UNC paths, eg

    xcopy F:\BackupTest\*.bak \\SQL02\H$\BackupTest\ /s /d

    But the SQL Server service account needs permissions. The 'H$' is an admin share, so the service account or the machine account would need admin permissions on the other server. If you create a regular share on the other server you can set granular permissions.