Backup query not returning differential backup info after AAG toggles

Good morning all,

I have a query that returns pivoted information on all FULL and Differential backups for my AAG SQL instances that works (so I thought) very well, but when the AAG toggles after the FULL backup is taken, the next day the query fails to pull the differential information. In short server1 primary had a full backup taken on Friday night by NetBackup then on Saturday the AAG toggles now having server2 as primary and NetBackup successfully performs a differential backup on it. My query though does not report on that backup having taken place. Attached is the code for your review, looking to see what I’m doing wrong. Thanks for guidance with this

SELECT

    @@SERVERNAME,
    M.name as DBName,
    [RecoveryModel] = M.recovery_model_desc,
    [State] = M.state_desc,

    FORMAT(ISNULL(M.D, '19000101'), 'MM/dd/yyyy hh:mm') as LastFull ,
    FORMAT(ISNULL(M.I, '19000101'), 'MM/dd/yyyy hh:mm') as LastDifferential,
    M.Software as 'Backup_Software_info'

FROM

(
    SELECT

        db.name,
        db.state_desc,
        db.recovery_model_desc,
        a.type,
        a.backup_finish_date,
        a.name as 'Software'

    FROM master.sys.databases AS db
    LEFT OUTER JOIN msdb.dbo.backupset AS a
      ON a.database_name = db.name

) AS Sourcetable

PIVOT

(
    MAX(backup_finish_date)
    FOR type IN
    (
        I,
        D
    )

) AS M --MostRecentBackup

WHERE name NOT IN

( N'master', N'msdb', N'model', N'tempdb', N'STIGMonitor' )  --Ignore system databases

and
  M.D > DATEADD(DAY, -7, GETDATE())   --Look back only 7 days of FullBackup   

and
    name in (SELECT name from sys.databases)  --Active Databases

ORDER BY name

I think by “toggles”, you mean it fails over to the other node?

The backups are recorded on the node where they run. If you always run your backups on the primary node you will need to query both nodes to get full backup information.

Good morning Graz, thank you for the reply

Yes, toggle meant the AAG falls over to the secondary replica. Both instances are queried, but the result only reports on the now secondary replica for the differential backups. The full backup from the previous friday is still reported on correctly, but the differentials are not reported correctly via my pivot query

Thanks

Maybe the differential backup is being converted to a FULL backup?