我有一个SQL查询,可将备份文件从一台计算机移动到另一台计算机。在这里,我需要为变量@ bkpFileName1指定每个备份名称。实际上,我需要移动最近使用的每个备份文件。我必须从磁盘驱动器中选择每个备份文件并相应地移动它。我该怎么做?
我的查询:
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE WITH OVERRIDE
GO
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
declare @date datetime
declare @dbname nvarchar(40)
DECLARE @cmd nvarchar(4000)
DECLARE @srcbkpLocation nvarchar(4000)
DECLARE @destbkpLocation nvarchar(4000)
DECLARE @bkpFileName nvarchar(4000)
DECLARE @bkpFileName1 nvarchar(4000)
set @destbkpLocation='\\ntp-228\Share_H\Monish'
SET @srcbkpLocation = 'E:\bckup\demo1'
SET @bkpFileName1 = 'WSI_NBQ_Dev_30_10_18.bak'
SET @cmd = 'robocopy '+@srcbkpLocation+' '+@destbkpLocation+'
'+@bkpFileName1+' '+'/MOV'
print @cmd
EXEC master.dbo.xp_cmdshell @cmd, NO_OUTPUT
EXEC master.dbo.sp_configure 'xp_cmdshell', 0
RECONFIGURE WITH OVERRIDE
GO
EXEC master.dbo.sp_configure 'show advanced options', 0
RECONFIGURE WITH OVERRIDE
GO