Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

backup sql database to network drive

Posted on 2014-01-17
6
Medium Priority
?
2,385 Views
1 Endorsement
Last Modified: 2014-02-27
I'm trying to backup my sql databases to a new mapped network drive and it is not seeing the drive.  I am trying to run the following command, but it is getting an error.

exec xp_cmdshell 'net use Z: "\\WDMYCLOUDEX4\SQL Backups"'

Is there something I am putting in wrong?
The backup drive is mapped to Z:
SQL server 2008.
1
Comment
Question by:TomBalla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Expert Comment

by:Patrick Bogers
ID: 39789297
Hi

You could try this

exec xp_cmdshell 'net use Z: "\\WDMYCLOUDEX4\SQL Backups" password /user:domain\username'
If not working rename the target replace the space by underscore and remove the double quotes.

Better practice is back-up locally and copyright it later to its final destination.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39789454
I recommend you to use the actual network path instead of the mapped letter drive. SQL account will not be able to see all the mapped drive from the UI.
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 39789686
Yes, just write to the UNC name directly; for example:

BACKUP DATABASE [whatever]
TO DISK = '\\WDMYCLOUDEX4\SQL Backups\whatever_yyyymmdd.BAK'
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 38

Expert Comment

by:Jim P.
ID: 39789910
SQL Server can't use mapped drives for anything. You have to use a UNC path as Scott mentioned. Also applies for reading data as well. And also make sure the SQL Service and SQL Service Agent logins have permissions to the share name.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39790291
Hi,

The real gottcha is figuring out exactly who SQL or the process is running as. It is this account that needs the drive mapped, and will take an agent or server reboot to pick up the new mapping.

Easiest all round in the more recent versions of SQL that know about url's and don't have to have the drive mapped. I did something similar to Patrick's suggestion for SQL 2000. That is, job step one is to map the drive regardless, step two is the backup.

HTH
  David
0
 
LVL 5

Accepted Solution

by:
rk_india1 earned 2000 total points
ID: 39791132
You have to use two separate step

One step to to map the drive or second step to backup the script.

net use z: \\computer\folder

I am also using the  direct network path for the backup purpose.

-Backup script for all user database------------------------------------------------------------

DECLARE @name VARCHAR(50) -- database name  
DECLARE @path VARCHAR(256) -- path for backup files  
DECLARE @fileName VARCHAR(256) -- filename for backup  
DECLARE @fileDate VARCHAR(20) -- used for file name

SET @path = '\\Ntp02A\SQLDBA_backups\Backup\Full\'  

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR  
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')  

OPEN db_cursor  
FETCH NEXT FROM db_cursor INTO @name  

WHILE @@FETCH_STATUS = 0  
BEGIN  
       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
       BACKUP DATABASE @name TO DISK = @fileName  

       FETCH NEXT FROM db_cursor INTO @name  
END  

CLOSE db_cursor  
DEALLOCATE db_cursor
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question