DECLARE @S1 VARCHAR(MAX),@S2 VARCHAR(MAX),@S3 VARCHAR(MAX),@S4 VARCHAR(MAX)
SELECT @S1 = ISNULL(@S1,'')+'
-----主体服务器备份数据库(完整和日志)
BACKUP DATABASE ['+NAME+'] TO DISK=''\\LYNC09.VL.CN\DB\'+NAME+'.BAK'' WITH INIT
BACKUP LOG ['+NAME+'] TO DISK=''\\LYNC09.VL.CN\DB\'+NAME+'.TRN'' WITH INIT
', @S2 = ISNULL(@S2,'')+'
-----镜像服务器还原数据库norecovery(完整和日志;)
----注意数据文件的路径及数据库所有者
EXECUTE AS LOGIN =''sa''
GO
RESTORE DATABASE ['+NAME+'] FROM DISK=''\\LYNC09.VL.CN\DB\'+NAME+'.BAK'' WITH NORECOVERY
RESTORE LOG ['+NAME+'] FROM DISK=''\\LYNC09.VL.CN\DB\'+NAME+'.TRN'' WITH NORECOVERY
',@S3=ISNULL(@S3,'')+'
/*下述操作也可用向导完成:脚本如下*/
---镜像服务器设置镜像伙伴
ALTER DATABASE ['+NAME+'] SET PARTNER=''TCP://LYNC07.VL.CN:5022''
',@S4=ISNULL(@S4,'')+'
---主体服务器设置镜像伙伴
ALTER DATABASE ['+NAME+'] SET PARTNER=''TCP://LYNC08.VL.CN:5022''
/*
增加见证服务器:
*/
ALTER DATABASE ['+NAME+'] SET WITNESS=N''TCP://LYNC09.VL.CN:5022''
go
'
FROM SYS.DATABASES
WHERE NAME IN('CPSDyn','LcsCDR','LcsLog','Lis','QoeMetrics','RgsConfig','RgsDyn','Rtcab','RtcShared','RtcXds','Xds')
AND recovery_model_desc='FULL'
PRINT @S1
PRINT @S2
PRINT @S3
PRINT @S4