Sql-server – Backing Up an AG with Ola Hallengren

availability-groupsbackupola-hallengrensql serversql server 2014

I'm trying to understand the labyrinth that is the rules about AG backups.I've got Ola Hallengren's scripts installed on machines TST01/TST02. 02 is the preferred replica for backups. I have an AG with AdventureWorks in it and one database outside the AG – DBAutility.

I have the below in my SQL Agent job on TST01.

sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q “EXECUTE [dbo].[DatabaseBackup] @Databases = ‘User_Databases’, @CopyOnly = ‘Y’,@Directory = N’C:\MyDirectory\’, @BackupType = ‘FULL’, @Verify = ‘Y’, @CleanupTime = 168, @CheckSum = ‘Y’, @LogToTable = ‘Y'” -b

When I run the job on TST01 I get a backup of DBAUtility taken from TST01 and written to that machine. I get no backup of AdventureWorks. I'm taking this approach from a post from Brent Ozar.

Brent on Ola H and AG Backups

I know Ola has other parameters for AG backups, but I couldn't seem to get that to work as expected either.

Best Answer

I do this a lot with my Availability Group backups (using Ola's scripts). Since you have @CopyOnly = 'Y', and you have a Secondary server set as your preferred replica for backups, Ola's script will ignore this backup on your Primary and use the Secondary server for the FULL_COPY_ONLY backups (if the script is run there).

If you were to do away with the @CopyOnly = 'Y' parameter, the scripts would take a FULL backup on your Primary server (FULLs and DIFFs are not allowed on Secondaries).

Ola's scripts are smart when it comes to Availability Groups. If you have a preferred secondary specified, his scripts will try to use it for any backups that don't HAVE to be done on the Primary. Because of this, I wound up creating identical backup jobs across my Primary and Secondary servers, and each one runs whichever backups are appropriate based on the current status of each server.