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

Backup on the Primary Replica in case of the Secondary Replica is down

$
0
0

I have 2 SQL Server replicas configured on SQL Server 2012 AlwaysOn. e.g. SQL1 & SQL2.

I have configured backup job on both SQL Server with the following statement. and the job occurs every 10 minutes.

  • declare @DBNAME sysname,@sqlstr varchar(500)
    set @DBNAME = 'dba'
    IF (sys.fn_hadr_backup_is_preferred_replica(@DBNAME)=0)
    BEGIN
          --Select 'This is not the preferred replica, exiting with success';
          RETURN -- This is a normal, expected condition, so the script returns success
    END
    --print '1'
    set @sqlstr = 'backup log dba to disk = ''E:\MSSQL\MSSQL11.MSSQLSERVER\MSSQL\Backup\dba_'+left(replace(replace(convert(varchar(30),getdate() ,126),'-',''),':',''),15)+'.trn'' with compression;';
    print @sqlstr;
    exec (@sqlstr)

I turned off SQL2 for Windows maintenance. So there is only SQL1 is online. Afterwards. I checked the backup folder and didn't see any new backup files was created after SQL2 was offline. I rerun the job. It still doesn't backup database on the Primary Replica.  Then I searched on SQL Server Book online. It says

Prefer Secondary
Specifies that backups should occur on a secondary replica except when the primary replica is the only replica online. In that case, the backup should occur on the primary replica. This is the default option.

According to what it says, it should backup on the Primary Replica. Does anyone experience this issue before?


Shawn


Viewing all articles
Browse latest Browse all 4689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>