Solved

backup sql database to network drive

Posted on 2014-01-17
6
1,812 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
6 Comments
 
LVL 19

Expert Comment

by:Patricksr1972
Comment Utility
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 26

Expert Comment

by:Zberteoc
Comment Utility
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 69

Expert Comment

by:ScottPletcher
Comment Utility
Yes, just write to the UNC name directly; for example:

BACKUP DATABASE [whatever]
TO DISK = '\\WDMYCLOUDEX4\SQL Backups\whatever_yyyymmdd.BAK'
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 38

Expert Comment

by:Jim P.
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now