You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backup-DbaDatabase - Improve error messages for mapped drive path failures
When SQL Server cannot access a drive-letter path (mapped drive), explain
that net use mappings are per user session and not visible to the SQL Server
service account, and suggest using a UNC path instead. Also detect OS Error 3
in backup failures and surface the same guidance in the catch block.
Fixes#10366
(do Backup-DbaDatabase)
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Copy file name to clipboardExpand all lines: public/Backup-DbaDatabase.ps1
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -163,6 +163,7 @@ function Backup-DbaDatabase {
163
163
Skips path validation checks before backup operations, useful when SQL Server has limited filesystem access.
164
164
Bypasses safety checks that normally prevent backup failures due to permissions or missing paths.
165
165
Use with caution as it may result in backup failures that could have been prevented.
166
+
Note: This does not help when using mapped drives (e.g. net use). Mapped drives are only visible to the user session that created them, not to the SQL Server service account. Use UNC paths (e.g. \\server\share\path) for network locations.
166
167
167
168
.PARAMETEROutputScriptOnly
168
169
Generates and returns the T-SQL BACKUP commands without executing them.
@@ -918,7 +919,11 @@ function Backup-DbaDatabase {
918
919
if (($BuildPath-eq$true) -or ($CreateFolder-eq$True)) {
$failreason+="SQL Server cannot check if $parentPath exists. You can try disabling this check with -IgnoreFileChecks"
922
+
if ($parentPath-match"^[A-Za-z]:\\") {
923
+
$failreason+="SQL Server cannot access $parentPath. Drive letter paths (e.g. $($parentPath.Substring(0,2))) are mapped per user session and are not visible to the SQL Server service account. Use a UNC path instead (e.g. \\server\share\path)."
924
+
} else {
925
+
$failreason+="SQL Server cannot access $parentPath. Verify that the SQL Server service account has read/write permissions to this path. You can bypass this check with -IgnoreFileChecks, but the backup will still fail if SQL Server cannot access the path."
Stop-Function-message "Backup of [$dbName] failed"-ErrorRecord $_-Target $dbName-Continue
1085
+
$errMsg="Backup of [$dbName] failed"
1086
+
if ($_.Exception.Message-like"*Operating system error 3*"-or$_.Exception.InnerException.Message-like"*Operating system error 3*") {
1087
+
$errMsg+=" | The SQL Server service account cannot find the backup path. If you used a mapped drive (e.g. net use), use a UNC path instead (e.g. \\server\share\path), as mapped drives are not visible to the SQL Server service account. Run Test-DbaPath -SqlInstance $($server.Name) -Path `"$humanBackupFile`" to verify accessibility from SQL Server."
0 commit comments