· Emad Adel · Security  · 2 min read

Make Network Path Visible For SQL Server Backup and Restore in SSMS

There are two main approaches to make a network path visible for SQL Server backup and restore operations in SSMS: 1. Using UNC Path:

There are two main approaches to make a network path visible for SQL Server backup and restore operations in SSMS: 1. Using UNC Path:

There are two main approaches to make a network path visible for SQL Server backup and restore operations in SSMS:

  1. Using UNC Path:

This is the recommended approach and avoids complications with drive mappings. Simply specify the full Universal Naming Convention (UNC) path to the network location in your backup or restore statements.

Here’s an example:

SQL
BACKUP DATABASE MyDatabase
TO
 DISK
=
 N
'\\Servername\ShareName\MyDatabaseBackup.bak'
  1. Mapping Network Drive (with caution):

If you prefer using a drive letter, you can map the network drive. However, keep in mind that the SQL Server service account needs access to the mapped drive. Here’s what to consider:

  • Map the drive permanently: Use the net use command with the /PERSISTENT:YES flag to ensure the drive remains mapped even after a reboot.

OR

  • Use xp_cmdshell (with caution):

This method involves enabling the xp_cmdshell extended stored procedure, which can be a security risk if not handled carefully. Only use this approach if necessary and follow these steps:

  1. Enable xp_cmdshell (with caution):
SQL
EXEC
 sp_configure
'show advanced options'
,
1
;
GO
RECONFIGURE;
GO

EXEC
 sp_configure
'xp_cmdshell'
,
1

GO
RECONFIGURE
GO
  1. Map the drive using xp_cmdshell:
SQL
EXEC
 xp_cmdshell
'net use H: \\Servername\ShareName /USER:Domain\Username'

Replace:

  • H: with your desired drive letter.
  • \\Servername\ShareName with the actual network path.
  • Domain\Username with the credentials that have access to the share (if necessary).
  1. Verify the mapping:
SQL
EXEC
 xp_cmdshell
'Dir H:'
  1. Use the mapped drive letter in your backup or restore statements (e.g., H:\MyDatabaseBackup.bak).
  2. Remember to disable xp_cmdshell after use for security reasons:
SQL
EXEC
 sp_configure
'xp_cmdshell'
,
0

GO
RECONFIGURE
GO

Important points:

  • Mapping a drive might not work if the SQL Server service account doesn’t have access to the share.
  • Using xp_cmdshell carries security risks. Enable it only when necessary and disable it afterward.

Recommendation:

For better security and consistency, it’s generally recommended to use the UNC path directly in your backup and restore statements.

Back to Blog

Related Posts

View All Posts »
تسجيل الدخول الموحد (SSO)

تسجيل الدخول الموحد (SSO)

♦️تسجيل الدخول الموحد (SSO): مفتاح واحد لفتح العديد من الأبواب تخيل أنك تمتلك مجموعة كبيرة من المفاتيح، لكل باب في منزلك مفتاح مختلف. تخيل العناء الذي ستتعرض له كل يوم لتذكر كل هذه المفاتيح وإدارتها.

عالم الكمبيوتر "روبرت نورتون نويس

عالم الكمبيوتر "روبرت نورتون نويس

يحتفل صباح اليوم الاثنين 12-12 محرك البحث الشهير "جوجل" بذكرى ميلاد عالم الكمبيوتر "روبرت نورتون نويس"، وذلك من خلال تغيير شعاره الخاص به إلى صورة رمزية للعالم الذى سجل باسمه 16 براءة اختراع. ويعد نويس من الشخصيات...

مصر بتبقى Hub عالمي للكلاود.. وده بيعني إيه عليك؟

مصر بتبقى Hub عالمي للكلاود.. وده بيعني إيه عليك؟

مليار دولار استثمارات، Hyperscale Data Center، وشركات عالمية بتدق باب القاهرة — فرصة تاريخية لكل اللي شغلتهم في التكنولوجيا تحالف Reniergy Group بيدرس إنشاء مركز بيانات ضخم في مصر باستثمارات وصلت لـ مليار دولار ....