if (select ars.role_desc from sys.dm_hadr_availability_replica_states ars inner join sys.availability_groups ag on ars.group_id = ag.group_id where ag.name = 'SQLKNAG1' and ars.is_local = 1) = 'SECONDARY'
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'P:\atlantisbackup1\AtlantisDB_', @gunTar, '.bak') set @path2 = CONCAT( N'Q:\atlantisbackup2\AtlantisDB_', @gunTar, '.bak02') set @path3 = CONCAT( N'S:\atlantisbackup3\AtlantisDB_', @gunTar, '.bak03') set @path4 = CONCAT( N'U:\atlantisbackup4\AtlantisDB_', @gunTar, '.bak04')
BACKUP DATABASE [AtlantisDB] TO DISK = @path1, DISK =@path2, DISK =@path3, DISK =@path4 WITH NOFORMAT, NOINIT, COPY_ONLY, NAME = N'AtlantisDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 5