How SQL remotely backs up a database to a local

Source: Internet
Author: User

How SQL remotely backs up a database to a local

--1, enabling xp_cmdshell Use Masterexec sp_configure ' show advanced options ', 1RECONFIGURE with overrideexec sp_configure ' xp_cmdshell ', 1RECONFIG URE with overrideexec sp_configure "show advanced options", 0RECONFIGURE with OVERRIDE

--2, using variables for backup declare @db sysnamedeclare @dbpath varchar Set @db = ' Shenyin '--file name based on database name + date yyyymmdd+ extension set @dbpath = ' d:\ ' + @db +convert (varchar), GETDATE (), () + '. Bak ')

 --3, build a mapping exec master in SQL . xp_cmdshell ' net use Y:\\192.168.0.156\DBBackup"Jindou"/user:192.168.0.156\administrator '/* Description: Y: Is the Map network path corresponding to the local drive letter 192.168.0.156 is my native IP dbbackup is my native shared folder Administrator is the login username "Jindou" is the password for the administrator user * /--4, Backup (@db is the name of the database to be backed up)backup database @db to[email protected] --5, copydeclare @copypath varchar set @copypath = ' Copy' + @dbpath + 'Y: ' Select @copypathexec Master. xp_cmdshell @copypath --6, delete (this sentence can be removed)declare @deletepath varchar set @deletepath = ' del' + @dbpathSelect @deletepathexec Master. xp_cmdshell @deletepath --7, delete map exec master after completion . xp_cmdshell ' net use Y:/delete '

--8, close xp_cmdshell

How SQL remotely backs up a database to a local

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.