use [ElasticSearch] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('ElasticSearch'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticSearch\FULL\ElasticSearch_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticSearch\FULL\ElasticSearch_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticSearch\FULL\ElasticSearch_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticSearch\FULL\ElasticSearch_', @gunTar, '.bak04')
BACKUP DATABASE [ElasticSearch] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'ElasticSearch-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO -------------------- use [ElasticTransaction] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('ElasticTransaction'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticTransaction\FULL\ElasticTransaction_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticTransaction\FULL\ElasticTransaction_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticTransaction\FULL\ElasticTransaction_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ElasticTransaction\FULL\ElasticTransaction_', @gunTar, '.bak04')
BACKUP DATABASE [ElasticTransaction] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'ElasticTransaction-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO --------------------
use [ISD] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('ISD'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ISD\FULL\ISD_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ISD\FULL\ISD_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ISD\FULL\ISD_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ISD\FULL\ISD_', @gunTar, '.bak04')
BACKUP DATABASE [ISD] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'ISD-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO
------------ use [KNetStats] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('KNetStats'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetStats\FULL\KNetStats_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetStats\FULL\KNetStats_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetStats\FULL\KNetStats_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetStats\FULL\KNetStats_', @gunTar, '.bak04')
BACKUP DATABASE [KNetStats] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'KNetStats-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO ----------------
use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('master'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path = CONCAT( N'R:\backup\master_', @gunTar, '.bak')
BACKUP DATABASE [master] TO DISK = @path WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'master-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO -------------- use [msdb] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('msdb'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path = CONCAT( N'R:\backup\msdb_', @gunTar, '.bak')
BACKUP DATABASE [msdb] TO DISK = @path WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'msdb-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO ------------- use [ArchiveDB] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('ArchiveDB'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ArchiveDB\FULL\ArchiveDB_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ArchiveDB\FULL\ArchiveDB_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ArchiveDB\FULL\ArchiveDB_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\ArchiveDB\FULL\ArchiveDB_', @gunTar, '.bak04')
BACKUP DATABASE [ArchiveDB] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'ArchiveDB-Full Database BYackup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END GO --------------- use [KNetLogs] GO use [master] GO DECLARE @preferredReplica int
SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('KNetLogs'))
IF (@preferredReplica = 1) BEGIN declare @gunTar nvarchar(20), @path nvarchar(100) ,@path1 nvarchar(100), @path2 nvarchar(100), @path3 nvarchar(100), @path4 nvarchar(100) set @gunTar = format(getdate(), 'yyyyMMdd_HHmmss')
set @path1 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetLogs\FULL\KNetLogs_', @gunTar, '.bak') set @path2 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetLogs\FULL\KNetLogs_', @gunTar, '.bak02') set @path3 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetLogs\FULL\KNetLogs_', @gunTar, '.bak03') set @path4 = CONCAT( N'R:\backup\SQLCLS01$SQLKNAG1\KNetLogs\FULL\KNetLogs_', @gunTar, '.bak04')
BACKUP DATABASE [KNetLogs] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'KNetLogs-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5 END
EXEC msdb.dbo.sp_start_job @job_name = N'DBA_Copy_StoreOnceOtherDB_mail'; GO