标签:
declare @DBName nvarchar(max)
declare @BakName nvarchar(max)
--在这里修改数据库名称
select @DBName=‘[LFBMP.PO]‘
--指定保存路径\\192.168.100.2\d$\DBBak
select @BakName=‘\\192.168.100.2\d$\DBBak\aa‘+REPLACE(@DBName,‘.‘,‘_‘)+Convert(char(10),getdate(),120)+‘.bak‘
--启用网络映射盘
--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‘
--本地磁盘
--select @BakName=‘D:\dbbak\‘+REPLACE(@DBName,‘.‘,‘_‘)+Convert(char(10),getdate(),120)+‘.bak‘
declare @BakSQL nvarchar(max)
select @BakSQL=‘Backup Database ‘+@DBName+‘ To disk=‘‘‘+@BakName+‘‘‘ with init,nounload ‘
print @BakSQL
exec (@BakSQL)
--启用xp_cmdshell(exec master..xp_cmdshell报错就用下面的)
--EXEC sp_configure ‘show advanced options‘, 1;
--RECONFIGURE;EXEC sp_configure ‘xp_cmdshell‘, 1;
--RECONFIGURE;
标签:
原文地址:http://www.cnblogs.com/q149072205/p/5585031.html