I have an AG with one primary replica and one secondary replica. I have created a script that queries transaction log backups from these database replicas and restores them to a target database.
Recently one user removed one secondary database from the AG and started using it as a standalone database as explained here https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/remove-a-secondary-database-from-an-availability-group-sql-server?view=sql-server-2017. The user also started a backup chain of this database.
The script now fails to restore as the recovery fork guid has changed on the secondary database.
Is there a way to detect if a database has left the AG so that in the script while I query the backupsets, I can skip the database if it is no longer part of the AG?