Solved

backup sql database to network drive

Posted on 2014-01-17
6
2,018 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 69

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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