zzgzyyz 发表于 2018-10-16 06:26:04

SQL Server 远程备份数据库

-- 创建网络映射(Y是盘符;IP地址后面要带共享文件夹的名称;password是密码,双引号引起;account是远程电脑的登录名)  
exec master..xp_cmdshell 'net use Y: \\192.168.0.69\sqlbackup "password" /user:192.168.0.69\account'
  
-- 按日期时间做文件名(注意路径中的文件夹,需要先建立好)
  
declare @filename varchar(200)
  
select @filename = 'Y:\DB\' + replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ','-'),':','') + '.bak'
  
-- 执行备份(DB是要备份的数据库名称)
  
backup database to disk = @filename
  
-- 删除网络映射(Y是盘符,同上)
  
exec master..xp_cmdshell 'net use Y: /delete'


页: [1]
查看完整版本: SQL Server 远程备份数据库