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