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

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.

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

xtrabackup_restore.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.

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.

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.