Quantcast
Channel: SQL Server High Availability and Disaster Recovery forum
Viewing all articles
Browse latest Browse all 4689

Backup integrity checks failing for AlwaysON Availability Group database backups using maintenance plans on non-preferred replicas

$
0
0

We configure maintenance plans on all the replicas to take the backups of AlwaysON Availability Group databases. On the preferred replica, the backups happen and on the rest of the replicas backups don't happen. However, when we enable Backup Integrity check in maintenance plans, the job is failing on non-preferred replicas (saying that it is unable to find the backup file while verifying the backup file). When we checked, it is the issue with maintenance plans with AlwaysON Availability Groups. Following is the code generated by SSMS when a maintenance plan is created for an AlwaysON Availability Group (for taking backup with backup integrity check enabled).

DECLARE @preferredReplica int

SET @preferredReplica = (SELECT [master].sys.fn_hadr_backup_is_preferred_replica('AG1'))

IF (@preferredReplica = 1)
BEGIN
    BACKUP DATABASE [AG1] TO  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\AG1_backup_2018_07_29_230055_7033159.bak' WITH NOFORMAT, NOINIT,  NAME = N'AG1_backup_2018_07_29_230055_7033159', SKIP, REWIND, NOUNLOAD,  STATS = 10
END
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'AG1' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'AG1' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''AG1'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Backup\AG1_backup_2018_07_29_230055_7033159.bak' WITH  FILE = @backupSetId,  NOUNLOAD,  NOREWIND

On non-preferred replicas (ie where  sys.fn_hadr_backup_is_preferred_replica returns 0), the backup doesn't happen but backup integrity check is still happening because the command RESTORE VERIFY is outside of IF condition for checking whether the replica is preferred or not. If RESTORE VERIFY is also in the IF block, then it will also be skipped.

Can someone let me know if there is a workaround for this issue within the maintenance plans? I know that if we configure our own jobs to backup and backup verification, we can avoid this issue but we use maintenance plans on all the servers in our environment.


Viewing all articles
Browse latest Browse all 4689

Trending Articles