# Does xtrabackup flush the binlog files after successful backup

**URL:** <https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056>\
**Category:** Percona XtraBackup\
**Created:** [June 23, 2023, 3:43am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056 "2023-06-23T03:43:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnwcarew](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/johnwcarew/32/6855_2.png) [@johnwcarew](https://forums.percona.com/u/johnwcarew)\
**Post date:** [June 23, 2023, 3:43am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/1 "2023-06-23T03:43:26Z")

</div>

As the title states, I’m trying to find out what will cause the binlog files to clear after a backup. Does xtrabackup do this?

---

<div class="post-metadata">

**Author:** ![Mughees\_Ahmed](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/mughees_ahmed/32/9028_2.png) [@Mughees\_Ahmed](https://forums.percona.com/u/Mughees_Ahmed)\
**Post date:** [June 23, 2023, 4:01am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/2 "2023-06-23T04:01:27Z")

</div>

This is was actually xtrabackup does with binlogs

> _xtrabackup_ will use `LOCK BINLOG FOR BACKUP` to block all operations that might change either the binary log position or `Exec_Master_Log_Pos` or `Exec_Gtid_Set` (i.e. source binary log coordinates corresponding to the current SQL thread state on a replication replica) as reported by `SHOW MASTER/SLAVE STATUS`. _xtrabackup_ will then finish copying the REDO log files and fetch the binary log coordinates. After this is completed _xtrabackup_ will unlock the binary log and tables.
> 
> Finally, the binary log position will be printed to `STDERR` and _xtrabackup_ exits, returning 0 if all went OK.

you can read full details about how percona xtrabackup works here [How Percona XtraBackup Works - Percona XtraBackup](https://docs.percona.com/percona-xtrabackup/2.4/how_xtrabackup_works.html)

---

<div class="post-metadata">

**Author:** ![johnwcarew](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/johnwcarew/32/6855_2.png) [@johnwcarew](https://forums.percona.com/u/johnwcarew)\
**Post date:** [June 23, 2023, 4:05am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/3 "2023-06-23T04:05:38Z")

</div>

So is that a no? If not, how does the binlog files get cleaned up after a backup?

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [June 23, 2023, 4:41am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/4 "2023-06-23T04:41:37Z")

</div>

Hello John,

The answer is No. Xtrabackup is not going to clear binlogs.

(I’m going to assume by “cleanup” you meant “purge”.)

Binlog file rotation/ cleanup have no direct relation Xtrabackup; it does not produce them nor does it back-them-up. To rotate binary logs, you may use " [`expire_logs_days`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_expire_logs_days)" (deprecated) or in new versions " [`binlog_expire_logs_seconds`](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds)".

If you need to purge binary logs after (xtra)backup, you will have to do that manually.

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![johnwcarew](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/johnwcarew/32/6855_2.png) [@johnwcarew](https://forums.percona.com/u/johnwcarew)\
**Post date:** [June 23, 2023, 4:47am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/5 "2023-06-23T04:47:55Z")

</div>

So, is it ok to purge binlogs as long as all replicas are caught up to same position as source server? It won’t cause corrupt backups?

I come from a MsSql background, where the logs are transaction logs and you can’t delete/flush them until a successful backup. Does MySql not work like this?

---

<div class="post-metadata">

**Author:** ![kedarpercona](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/kedarpercona/32/809_2.png) [@kedarpercona](https://forums.percona.com/u/kedarpercona)\
**Post date:** [June 23, 2023, 5:33am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/6 "2023-06-23T05:33:33Z")

</div>

Hi John,

> So, is it ok to purge binlogs as long as all replicas are caught up to same position as source server? It won’t cause corrupt backups?

- As long as replicas are caught-up, you may purge the binlogs on master.
- It should not corrupt the backups.
- BUT remember, you don’t want to purge the binlogs for a possible [the point in time recovery] ([MySQL Point in Time Recovery the Right Way](https://www.percona.com/blog/mysql-point-in-time-recovery-right-way/)) requirement.

> I come from a MsSql background, where the logs are transaction logs and you can’t delete/flush them until a successful backup. Does MySql not work like this?

The prime objective of binary logs in MySQL is Replication. Binary log records the DML/DDL changes /w timestamps.  
Some example usage:

> > Thus they can also be used in point in time recovery, for eg: You have full backup of yesterday and binlogs until now you can restore it as:
> > 
> > - restore a fullbackup
> > - covert binlog to “SQL” and run those SQL changes against restored database to bring it back to last available state.
> > 
> > If you want to setup a replication then:
> > 
> > - restore a full backup on “replica node”
> > - issue “change source to” command, and MySQL will then read binlogs from master. Ofcourse you will need to mention the binlog co-ordinates to start the replication from noted in Xtrabackup.

Binlogs are not required for server functionality and MySQL can run with them disabled.  
What you’re probably referring to are “redo logs” and “undo logs” and I’d not really touch them 🙂

Again, we don’t really touch binary logs along with backup. It is better be managed by the configuration options (expire\_logs\_days / binlog\_expire\_logs\_seconds); mysql will automatically purge the binary logs after that duration. Most common days I have seen is like a week, but again, that depends on disk size and RPO/RTO objectives.

Thanks,  
K

---

<div class="post-metadata">

**Author:** ![Marcelo\_Altmann](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/marcelo_altmann/32/11299_2.png) [@Marcelo\_Altmann](https://forums.percona.com/u/Marcelo_Altmann)\
**Post date:** [June 23, 2023, 11:30am UTC](https://forums.percona.com/t/does-xtrabackup-flush-the-binlog-files-after-successful-backup/23056/7 "2023-06-23T11:30:25Z")

</div>

Hi @johnwcarew ,

Let me clarify one thing. As part of the backup we do rotate the binlog by executing `FLUSH NO_WRITE_TO_BINLOG BINARY LOGS` this will essentially create a new binlog and every new DML after the backup will belong to this new log.

I hope it clarifies your question.
