Solved

backup sql database to network drive

Posted on 2014-01-17
6
1,858 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
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 26

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

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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