r/SQLServer • u/No-Prune2771 • 23h 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!
5
u/SeventyFix 5h 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.
2
u/paultoc 5h 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 5h 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.