Solved

backup sql database to network drive

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

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 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
migrate a SQL 2008 to 2016, 2 45
shrink table after huge delete 2 28
Display SQL 2008 last modified/update Database 11 50
T-SQL: problem comparing datetime 4 50
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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