# Taking backups on an availability group

> Schedule COPY_ONLY full backups and log backups on every replica of an availability group with Ola Hallengren, clean up with dbatools.
>
> Source : https://www.pachadata.com/en/docs/howtos/database-maintenance/backup-ag/
> Author : Rudi Bruchez · updated 2026-10-14
> Markdown version of the page, for tools and LLMs. The HTML page is the reference.


1. Download and install [Ola Hallengren's procedure](https://ola.hallengren.com/sql-server-backup.html).
2. Schedule `COPY_ONLY` full backups on each replica. This assumes the availability group is configured to prefer backups on the secondary replica.
   To check that, use [this query](https://github.com/rudi-bruchez/tsql-scripts/blob/main/hadr/availability-groups.sql) and look at the `automated_backup_preference` column.
3. Schedule log backups on each replica. Ola Hallengren's procedure automatically runs the backup on the preferred replica.
   You can use [the example calls on my GitHub](https://github.com/rudi-bruchez/tsql-scripts/blob/main/database-administration/dba-database/012.ola-backups-ag.sql).
4. To delete the old backups, on a schedule if you want, you can use [dbatools](https://dbatools.io/download/) and this command:

```powershell
Remove-DbaBackup -Path '\\backup-server\repo$\CLUSTER-SQL-AG\MyDatabase\' -BackupFileExtension bak -RetentionPeriod 48h
```


---

## About the author

Rudi Bruchez, independent SQL Server consultant since 2006: performance audits, tuning, migrations, high availability and training. For an audit or hands-on help on your server: https://www.pachadata.com/en/contact/ (remote audit: https://www.pachadata.com/en/services/remote-sql-server-audit/).
