r/SQLServer • • 1d ago

Question SQL Server Always On backup best practices

Hi everyone,

I have a SQL Server 2019/2022 Always On Availability Group with two replicas (primary and secondary), accessed through a SQL Listener.

I want to configure weekly full, daily differential, and hourly transaction log backups using the Maintenance Plan Wizard.

My questions:

* Should I create the maintenance plans on both replicas or only the primary?

* How can I ensure backups continue automatically after a failover?

* Is using maintenance plans a good approach, or should I use custom SQL Agent jobs instead?

I'd appreciate any advice or production best practices. Thanks!

6 Upvotes

8 comments sorted by

9

u/SeventyFix 22h ago

I'm sure that there are other ways, but I use Ola Hallengren's solution (free and commonly used). Since I don't use readable secondary replicas, I strictly backup on primary. I have a job on each server that runs every couple is minutes to check if the current instance is the primary replica and enables/disables SQL Agent jobs based on requirements. Backup jobs are enabled only on primary replicas (except for system databases). Backups are written directly to S3.

7

u/paultoc 22h ago

You don't actually need a job to check if it's primary. I belive ola job skip's second db automatically. You just need to set backup preference to primary in ag config.

If you want a single folder for ag backups irrespective of which node is primary. I would suggest testing out configuring a dedicated backup job for AG databases on both nodes pointing to the same folder/container

1

u/preza 17h ago

This is the way. Second this comment.

1

u/SirGreybush 1 21h ago

THIS. I so hate maintenance plans with a passion.

I want it to work, as a job with notifications that are detailed as to why it failed when it does, and variable naming outputs for long term storage of monthly fulls.

Nothing like a weird data rule and we need to go back in time years ago.

Spin up a temp vm with dev edition, restore the BAK and compare against Prod. This saved our bacon a few times.

Long term storage on low cost NAS boxes or low speed high capacity Azure storage.

2

u/paultoc 22h ago

As someone else commented before go for Ola Hallemgren maintenance job. It's the best.

Just scheduled the backup jobs on both nodes. And set AG backup preference to primary. This will take care of backup even after fail-over

2

u/MaleficentRock3994 22h ago

I’d put the same SQL Agent jobs and schedules on both replicas. The listener handles connections, but the jobs live on each instance. What we’ve done is keep a separate Agent job running on both that checks which replica is primary for the AG. It enables the jobs that should run on the primary and disables them on the secondary. After a failover, the next check flips them over.

I typically use Ola Hallengren’s scripts over the Maintenance Plan Wizard because I find them more customizable. They’re pretty standard in the SQL Server community. If you’ve got a long-running backup on a multi-terabyte database, you can configure a striped backup or adjust how SQL Server handles backup I/O. A few parameters you can set are:
@NumberOfFiles sets how many files SQL Server writes to in parallel for a striped backup.
@BufferCount sets the number of I/O buffers used for the backup.
@MaxTransferSize sets the maximum number of bytes per transfer.

1

u/zrb77 16h ago

Ola is the best solution.

1

u/_edwinmsarmiento 1 15h ago

I want to configure weekly full, daily differential, and hourly transaction log backups

What's your recovery point/recovery time objective (RPO/RTO) for high availability? What about for disaster recovery?

Having backups is a MUST.

But configuring backups should be a result of your business requirements, not just some random recommendations from your favourite AI tool (or search engine).

Because the next thing you need to do is to TEST whether or not those backup types do MEET your RPO/RTO requirements for HA and DR.

The right "BEST PRACTICE" is the one that MEETS your business requirements.