Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL server 7
Database 6
Tips 5
Tricks 5
#SQLServer 3
Backup 2
MSSQL 1
'E0' 1
isnumeric 1
Issues 1

Archive · View All
December 2011 4
March 2012 2
January 2012 1

Raghunath Bhandari's Blog

MSSQL Backup to Map Drive

Dec 12 2011 9:06PM by Raghunath Bhandari   

We can backup a SQL Server database to a mapped drive using the following script


1) First it will create Map Drive in Local PC
2) Backup the Database.
3) Delete the Map Drive, so that next time the same script can be used.





EXEC master..xp_cmdshell 'net use z: "\\192.168.1.93\share" password /user:user1'

GO



BACKUP DATABASE DB1
TO DISK='z:\db1.bak' WITH INIT

GO



EXEC master..xp_cmdshell 'net use z: /delete'

GO


Tags: Database, SQL server, Mssql tips, MSSQL Backup to Map Drive, Backup, DBA, #SQLServer,


Raghunath Bhandari
183 · 1% · 253
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

4  Comments  

  • There is no need to map a drive in order to put a backup on remote storage. The BACKUP DATABASE command will directly accept a UNC path

    BACKUP DATABASE DB1 TO DISK='\\192.168.1.93\share\db1.bak'
    

    Here are a few benefits of directly using a UNC path: NOT a good idea to execute commands through xp_cmdshell that can trigger an error. For example, let's say that the Z: drive has already been mapped or that \192.168.1.93\share is unavailable. How do you handle those situations? Directly using a UNC path: if the path is unavailable, the BACKUP DATABASE command will throw a trappable error.

    Security: If you grant the SQL Server Service Account the ability to see the share and read/write to the directory, that's all you need. With an xp_cmdshell implementation, you are forced to hard-code a user account and password. Not only is this NOT secure, it's a maintenance problem waiting to happen. What do you do when the password has to be changed?

    commented on Jan 5 2012 12:01AM
    Marc Jellinek
    97 · 2% · 546
  • Hi Marc,

    Thanks for your nice comments,

    Can we run the Bulk insert using UNC path or not ? or previous version also support the same or not ?

    In your question "what do you do when the password has to be changed?" - Each time that script is using the latest password so password is not issue i think .

    commented on Jan 5 2012 2:37AM
    Raghunath Bhandari
    183 · 1% · 253
  • Yes, BULK INSERT can use a UNC path:

    From SQL Server Books Online:

    datafile must specify a valid path from the server on which SQL Server is running. If datafile is a remote file, specify the Universal Naming Convention (UNC) name. A UNC name has the form \Systemname\ShareName\Path\FileName. For example, \SystemX\DiskZ\Sales\update.txt.

    In regards to saving the password... you manually type in the commands to take a backup each time? Backups should be scripted and scheduled. The frequency is usually determined by the businesses needs (and tolerance for data loss), but at a minimum I'd suggest a full backup daily with either differential or transaction log backups hourly.

    commented on Jan 5 2012 8:10AM
    Marc Jellinek
    97 · 2% · 546
  • Thanks for sharing your views !

    commented on Jan 5 2012 11:20AM
    Raghunath Bhandari
    183 · 1% · 253

Your Comment


Sign Up or Login to post a comment.

"MSSQL Backup to Map Drive" rated 5 out of 5 by 2 readers
MSSQL Backup to Map Drive , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]