SQL Server Backup to Network disk network mapping disk

Source: Internet
Author: User
Tags getdate

declare @DBName nvarchar (max)
declare @BakName nvarchar (max)
--Modify the database name here
Select @DBName = ' [Lfbmp. PO] '
--Specify the save path \\192.168.100.2\d$\DBBak
Select @BakName = ' \\192.168.100.2\d$\DBBak\aa ' +replace (@DBName, '. ', ' _ ') +convert (char), GETDATE (), +) + '. Bak '
--Enable network mapping disk
--exec Master. xp_cmdshell ' net use \\192.168.1.2\d\DBBak password/user:192.168.1.2\administrator '
--exec Master. xp_cmdshell ' net use \\192.168.1.2\d\dbbak/delete '
--Local Disk
--select @BakName = ' D:\dbbak\ ' +replace (@DBName, '. ', ' _ ') +convert (char (), GETDATE (), +) + '. Bak '

declare @BakSQL nvarchar (max)
Select @BakSQL = ' Backup Database ' [email protected]+ ' to disk= ' [e-mail protected]+ ' with Init,nounload '
Print @BakSQL

EXEC (@BakSQL)


--Enable xp_cmdshell (exec master). xp_cmdshell error is used below)
--exec sp_configure ' show advanced options ', 1;
--reconfigure; EXEC sp_configure ' xp_cmdshell ', 1;
--reconfigure;

SQL Server Backup to Network disk network mapping disk

Related Article

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.