We recently ran into an issue with one of our environments where the Microsoft SQL Server experienced corruption in the database log. This issue is usually discovered when you attempt to create a new backup and it fails with the message “BACKUP detected corruption in the database log”
Resolving this issue is normally fairly easy (set the database from a Full Recovery Model to simple and then back again) but it gets a bit more complex when you database is replicated via an AlwaysOn High Availability Group. Here are the steps to fix it (assuming no other databases are in the AAG).
1. Remove Secondary Replica – First we need to stop replication to the secondary replica. To do this we are going to connect to the primary node in our cluster and right click on the SECONDARY replica. Then we select “Remove from Availability Group” and follow the wizard.
2. Remove Database from AAG – Next we need to remove the database from the AAG by right clicking on it under the Availability Databases folder and selecting “Remove Database from Availability Group”
At this point you should have your primary node as the only member of the AAG with no databases associated. At this point you are going to delete the database from the SECONDARY node. Your secondary server should now have no replicas, no availability databases and no database.
3. Next we need to change the remaining copy of the database on our primary node from Full to a Simple Recovery Model by right clicking on the database and selecting properties > Options.
4. Next we need to do a full backup of the database.
5. Repeat the steps in #3 but in this case change it from simple back to the original Full Recovery Model.
6. Backup the database again.
Now we are ready to re-add the secondary replica
7. On the primary server right click on the Available Replicas folder and select “Add Replica…”
Next you will need to select the “Add Replica” button and will be prompted to connect to your secondary server.
After this you will want to configure your replica. In our case we have selected to have the secondary copy of the database as readable as well as enabling automatic failover.
In the next screen you will need to configure your sync preferences. We are using a Full sync which requires a file share accessible by both SQL Servers. Using this file share SQL will run a backup and place it on the remote share and the secondary node will restore the database from this initial backup.
Follow the wizard and verify that everything passes
After this you can track the progress of the backup/restore/sync
With that you should have a working AlwaysOn Availability Group again!