Support

Site Restoration

#38227 Database restoration arbitrarily reports duplicate entry

Posted in ‘Site restoration’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

PHP version
8.0.26
CMS Type
Joomla!
CMS Version
3.10.11
Backup Tool Version
8.2.3
Kickstart version
7.12

Latest post by d2o on Monday, 26 December 2022 04:48 CST

d2o

Hi,

on restoration of a running site to a different domain, the installer reports a duplicate entry for one table. I tried re-doing the backup and re-restoring. It then reported some other duplicate entry than before.

The reported entry seems arbitrary and there is no duplicate key in the original table. Maybe some paging issue in the installer routine?

Any help appreciated.

Cheers and Merry Christmas,

Stefan

System Task
system
The ticket information has been edited by Stefan Schulz (d2o).

nicholas
Akeeba Staff
Manager

This can happen when backing up a table which does not have a single column primary key (e.g. an AUTONUMBER integer field) and which is getting written to during backup. In this case the native MySQL paging is used for going through the rows of the table without having to lock the table for the duration of the backup, making your site unreachable. Since MySQL does not have a strictly defined behaviour for paginating this kind of tables you may end up with a duplicate row in the backup output.

You can work around that on restoration by selecting the β€œUse REPLACE instead of INSERT” option in the Database Restoration page, before starting the restoration of the database. This option is in the right-hand column. By using a REPLACE INTO instead of INSERT INTO the duplicate row is silently re-inserted without raising a MySQL error.

Note that the above behaviour is not unique to Akeeba Backup. It is what you will see with MySQLDump itself unless you use the --lock-tables option. Of course, if you were to use MySQLDump with this option then you'd have the aforementioned problem: since the table is locked for reading your site stops working as reading from the table is no longer possible.

Generally speaking, running into this problem is very rare. If this happens with all your backups you probably have a very big table without an auto-number column which changes too frequently (at least once a minute). Most tables like that are temporary, or can otherwise be rebuilt. Is this a table you really need to backup the data of?

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

d2o

Hi Nicholas,

Thanks for the quick response (on a holiday!).

So I tried to restore with Replace instead of Update, but only to get a different (persistent) error on the creation of the table:

121 "Duplicate key on write or update"

I tried to post the SQL statement (from ACY mailing plugin) as shown in the error message, unfortunately, the ticket system blocks it. :)

As far as I can see, it does have a single PK with auto increment. Not sure, if the error comes from the secondary key.

I doubt, I can drop this table without breaking acymailing.

Thanks and all the best,
Stefan

nicholas
Akeeba Staff
Manager

This is easy to fix. It's caused by another table having a foreign key constraint with the same name.

In the database restoration page's right-hand site With Existing -> set to β€œDrop All”. All of the tables in that database will be dropped before restoration, regardless of their prefix. This ensures that any old / renamed tables won't get in your way. That's the reason I added this feature a few years ago :)

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

d2o

Hi Nicholas,

Thanks for the hint.

I set the table handling to "Same prefix", as there are other applications using the same database. So now I created a new DB to be able to use Drop All. And, of course, restoration worked perfectly fine. Even no duplicate keys anymore using INSERT.

Thanks a lot for your great support. πŸ‘

Best regards and Happy New Year,
Stefan

nicholas
Akeeba Staff
Manager

The problem with the previous database was that there was another table with the same constraint name. If I recall correctly, AcyMailing does not use the Joomla database table name metaprefix (#__) in the names of the constraints it creates. So, if you have another site using AcyMailing sharing the same database you can't install it on any other site. At least that was the case about a year and a half ago when I last took a look at it because my wife had reported the same issue to me.

Moreover, if you use the default option to backup (rename) tables on restoration the old AcyMailing table is renamed by substituting its table name prefix with bak_. This does not rename the constraints, though, so you end up with the same problem. Removing the bak_ tables manually and choosing an option which deletes existing tables (same prefix or all) also fixes this issue if you really want to use the same database.

It is always a good idea using a different database for different applications. You will typically get better performance and less headaches should a single table crash. The reasons are rather esoteric and have to do with how MySQL storage engines work, the database server configuration, as well as the Operating System and filesystem you are using.

Nicholas K. Dionysopoulos

Lead Developer and Director

πŸ‡¬πŸ‡·Greek: native πŸ‡¬πŸ‡§English: excellent πŸ‡«πŸ‡·French: basic β€’ πŸ• My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

d2o

Hm, at least in version 7 of acymailing it seems to use tables with the correct joomla preset. But I had a version 5 still installed, which might have been the issue.

Too late to check now, as I already uninstalled all the crap 😁

In hindsight, it did not make sense to reuse the same database, although it is simply a developer backup of the original side. Especially, as it is so easy to create a new one.

Best wishes
Stefan

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!