# Xtrabackup restore - incremental backup needs target prepared with apply-log-only

**URL:** <https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264>\
**Category:** Percona XtraBackup\
**Created:** [November 25, 2024, 2:47pm UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264 "2024-11-25T14:47:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IGGt](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@IGGt](https://forums.percona.com/u/IGGt)\
**Post date:** [November 25, 2024, 2:47pm UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264/1 "2024-11-25T14:47:26Z")

</div>

I Use Xtrabackup to backup several of my MySQL backups (all 8.0.39).

They all use an identical script.  
The initial backup is:

`xtrabackup ${MySQLConnectionString} --backup --slave-info --extra-lsndir="${LogsDir}" --target-dir="${CurrentDir}" --lock-ddl --no-server-version-check --register-redo-log-consumer`

and the incremental backups are done by

`xtrabackup ${MySQLConnectionString} --backup --slave-info --safe-slave-backup --extra-lsndir="${LogsDir}" --target-dir="${NewDir}" --incremental-basedir="${BaseDir}" --lock-ddl --no-server-version-check --register-redo-log-consumer`

I then have a restore script to test the restore process. This runs:  
`xtrabackup --prepare --apply-log-only --target-dir="${backup_dir}/1/"`

and each incremental backup is restored with  
`xtrabackup --prepare --target-dir="${backup_dir}/1" --incremental-dir="${backup_dir}/${n}"`

and finally the last incremental backup is applied with  
`xtrabackup --prepare --target-dir="${backup_dir}/1" --incremental-dir="${backup_dir}/${x}"`

This works fine on all of my databases, apart from one. During the restore it always fails to prepare backup days 3 onwards.  
So Day 1 is fine (initial backup)  
Day 2 is fine (incremental backup)

On Day 3, and all subsequent days it simply reports:  
`[Note] [MY-011825] [Xtrabackup] This target seems to be already prepared. [ERROR] [MY-011825] [Xtrabackup] applying incremental backup needs target prepared with --apply-log-only.`

Can anyone shed some light on what it is looking for that is missing on Day 3 (or is there but shouldn’t be). e.g. what is it looking for that tells it it has “already been prepared”. As far as I can tell there is no difference between any of my databases, but clearly there is something different.

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [November 26, 2024, 1:51am UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264/2 "2024-11-26T01:51:13Z")

</div>

We need to see some logs. Can you supply the logs for day 1 full prepare, day 2 incremental, and the day 3 attempt?

---

<div class="post-metadata">

**Author:** ![IGGt](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@IGGt](https://forums.percona.com/u/IGGt)\
**Post date:** [November 27, 2024, 2:19pm UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264/3 "2024-11-27T14:19:51Z")

</div>

[xtrabackup\_restore.txt](https://forums.percona.com/uploads/short-url/uN9l3cibG2vZT339w0gWyPHorTu.txt) (207.9 KB)  
Here are the logs for an initial backup (OK), first incremental (OK), and second and third (fail) incremental backups. I have removed most of the copy sections in the middle to save space.

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [November 27, 2024, 3:33pm UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264/4 "2024-11-27T15:33:27Z")

</div>

The error logs tell you exactly what went wrong and how to correct the issue:

> 2024-11-21T13:52:50.670859-00:00 0 [ERROR] [MY-011825] [Xtrabackup] applying incremental backup needs target prepared with --apply-log-only.

You must use `--apply-log-only` for every full and every incremental, except the very last incremental.

---

<div class="post-metadata">

**Author:** ![IGGt](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@IGGt](https://forums.percona.com/u/IGGt)\
**Post date:** [December 6, 2024, 11:00am UTC](https://forums.percona.com/t/xtrabackup-restore-incremental-backup-needs-target-prepared-with-apply-log-only/35264/5 "2024-12-06T11:00:06Z")

</div>

OK cheers. That has fixed it. It’s strange that it seemed to be working fine for a few years now on the other databases.
