Support

Akeeba Backup for Joomla!

#16086 Restore fails to create functions and triggers

Posted in ‘Akeeba Backup for Joomla! 4 & 5’
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

Joomla! version
n/a
PHP version
n/a
Akeeba Backup version
n/a

Latest post by nicholas on Monday, 20 May 2013 16:35 CDT

jcc
Mandatory information about my setup:

Have I read the related troubleshooter articles above before posting (which pages?)? Yes
Have I searched the tickets before posting? Yes
Have I read the documentation before posting (which pages?)? Yes
Joomla! version: 2.5.11
PHP version: 5.3.13
MySQL version: 5.5.24
Host: (optional, but it helps us help you)
Akeeba Backup version: 3.7.7

EXTREMELY IMPORTANT: Please attach a ZIP file containing your Akeeba Backup log file in order for us to help you with any backup or restoration issue. If the file is over 2Mb, please upload it on your server and post a link to it.

Description of my issue:
When restoring backup that includes database functions with embedded semi-colons (';'), the database restore returns an exception.

An example function (that I extracted from the backup archive) is:

CREATE FUNCTION `fn_Maintain_Account_mail_fee_code`(primary_remote_address_id int) RETURNS varchar(4) CHARSET latin1 begin declare other_address_country_code varchar(2); declare new_mail_fee_code varchar(4); if primary_remote_address_id <> 0 and primary_remote_address_id is not NULL then set other_address_country_code = (select country_code from other_address oa where oa.other_address_id = primary_remote_address_id ); case when other_address_country_code = 'US' or other_address_country_code = '' then set new_mail_fee_code = NULL; when other_address_country_code = 'CA' then set new_mail_fee_code = 'CAMA'; else set new_mail_fee_code = 'FRGN'; end case; else set new_mail_fee_code = NULL; end if; return new_mail_fee_code; end;;

Note the 2 semi-colons at the end of the function definition. To get these to properly restore, I had to redefine the statement delimiter in mysql as:

delimiter //
CREATE FUNCTION `fn_Maintain_Account_mail_fee_code`(primary_remote_address_id int) RETURNS varchar(4) CHARSET latin1 begin declare other_address_country_code varchar(2); declare new_mail_fee_code varchar(4); if primary_remote_address_id <> 0 and primary_remote_address_id is not NULL then set other_address_country_code = (select country_code from other_address oa where oa.other_address_id = primary_remote_address_id ); case when other_address_country_code = 'US' or other_address_country_code = '' then set new_mail_fee_code = NULL; when other_address_country_code = 'CA' then set new_mail_fee_code = 'CAMA'; else set new_mail_fee_code = 'FRGN'; end case; else set new_mail_fee_code = NULL; end if; return new_mail_fee_code; end//
delimiter ;

[BTW - I hit return after entering subject for this ticket and was surprised when it was created without my adding any issue information. Sorry!]

nicholas
Akeeba Staff
Manager
You're right. This bug has been there for nearly three years o_O Nobody had actually tested a restoration of a database containing functions, procedures or triggers. I have just uploaded a new dev release which should fix this issue. Please take a look at https://www.akeebabackup.com/download/akeebapro.html and download svn1953. You can use it on your site and try restoring the new backup. Please let me know if that does work.

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!

jcc
Nicholas - Thank you for you quick response!

I installed svn1953 on a test site and successfully created a backup. The restore to a new site failed with a different exception.

I tried submitting the information (twice) in this reply only to trigger your site protection (I assume due to the included SQL statements.) I have created and uploaded an attachment with the information.

nicholas
Akeeba Staff
Manager
I see what's going on. I've decided to follow a different approach, having the restoration engine detect functions/triggers/procedures and run the DELIMITER commands before and after the CREATE command. I've just uploaded a new dev release, svn1955. Can you please give it a go?

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!

jcc
I have installed svn1955 and the "Backup Now" button on the "Start a new backup" page does not work. The page is displayed, but Joomla and firebug report exceptions:

Joomla:

JError:1

Options for callback not valid


Call stack
# Function Location
1 JAdministrator->dispatch() JROOT\administrator\index.php:46
2 JComponentHelper::renderComponent() JROOT\administrator\includes\application.php:153
3 JComponentHelper::executeComponent() JROOT\libraries\joomla\application\component\helper.php:351
4 require_once() JROOT\libraries\joomla\application\component\helper.php:383
5 AkeebaDispatcher->dispatch() JROOT\administrator\components\com_akeeba\akeeba.php:40
6 FOFDispatcher->dispatch() JROOT\administrator\components\com_akeeba\dispatcher.php:140
7 AkeebaControllerBackup->execute() JROOT\libraries\fof\dispatcher\dispatcher.php:322
8 FOFController->execute() JROOT\administrator\components\com_akeeba\controllers\backup.php:23
9 AkeebaControllerBackup->add() JROOT\libraries\fof\controller\controller.php:873
10 FOFController->display() JROOT\administrator\components\com_akeeba\controllers\backup.php:28
11 FOFViewHtml->display() JROOT\libraries\fof\controller\controller.php:967
12 FOFView->display() JROOT\libraries\fof\view\html.php:123
13 JError::setErrorHandling() JROOT\libraries\fof\view\view.php:445
14 JError::raiseError() JROOT\libraries\joomla\error\error.php:375
15 JError::raise() JROOT\libraries\joomla\error\error.php:251

Firebug:

TypeError: $.browser is undefined
...pacity=helper.parent.css("opacity");this.tooltipText=this.title;$(this).removeAt...
gui-he...4ea9513 (line 29)

TypeError: $.manageAjax is undefined
var akeeba_ajax_manager = $.manageAjax.create('akeeba_ajax_profile', {
akeeba...4ea9513 (line 2342

nicholas
Akeeba Staff
Manager
Yes, I saw that after you posted. Long story cut short, fixed version svn1956 will be uploaded in 5 minutes. Don't you love it when you fix one problem and another one emerges?

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!

jcc
hmmm...getting the same errors with svn1956.

[edit] Just to be clear, the same Joomla and firebug error reports. I can not backup.

nicholas
Akeeba Staff
Manager
It can't be. I verified that the missing file (media/akeeba_strapper/js/akjqmigrate.js) is included in svn1956 and verified it's being loaded by installing it on 3 test sites. Can you please retry installing it twice without uninstalling it in between?

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!

jcc
I restarted wamp and exited browsers. I am trying to install, but it takes me to the "Start a new backup" page and then can't get any further. ...button does not work...

I have found the file in the zip, but not on the site. Should I try just placing the file into the directory?

nicholas
Akeeba Staff
Manager
Yes, please. Copy the fof directory into your libraries directory and the akeeba_strapper directory into your media directory.

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!

jcc
That worked. I now have a backup. Testing the restore...

It seems to work for the CMS database (has 3 triggers), but the secondary database is failing on a create view? Here is the message:

Database error processing line 0

Database server error reply:
ErrNo #0

SQL=CREATE OR REPLACE ALGORITHM=UNDEFINED VIEW `property_ownership` AS select ...

nicholas
Akeeba Staff
Manager
Perhaps the user of the second db doesn't have create view privileges? I don't know what to make with the error code 0 :s

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!

jcc
using root account on local system. has all privs...

nicholas
Akeeba Staff
Manager
I would try to run the query through phpMyAdmin (or any other MySQL tools), being logged in with the same username as the one you used in ANGIE. This usually yields at the very least a more meaningful error message.

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!

jcc
I think there is a cockpit error in what I did. It doesn't make any sense, because there are no tables created in the database and the view is created in the last of the 50 files.

I have just blown-away the directory tree and am starting the restore from scratch.

OK. Well it is, at least, getting an 'expected' error on the second database:

Database error processing line 27

Database server error reply:
ErrNo #0

SQL=DELIMITER //

I still don't understand it though. The CMS database has 3 triggers in it which have been successfully created. It seems strange that it fails on this statement in the second database, but did not in the first?

nicholas
Akeeba Staff
Manager
That's an awfully good question. I think the answer requires a level of understanding of MySQL that's above mine :(

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!

jcc
I think I found why it fails on my second database and not the first. The first (CMS) has only triggers that have a single statement (in attachment so it passes security filters)...and these triggers are created successfully. To test this, I modified the last SQL file of the cms database restore to include a few function definitions. That fails to restore with the same error as above on the delimiter:

Database server error reply:
ErrNo #0

SQL=DELIMITER //

I think I also understand why I got the view failure reported above. I failed to capture the exception before dismissing the message. When I re-ran the restore to get the exception, it said that it failed on the view, but I think it really failed on the next line, which was the function creation.

nicholas
Akeeba Staff
Manager
Does the trigger in the attachment work or does it fail?

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!

jcc
Sorry for not being clear. The trigger in the attachment succeeds. It is the create function statements that fail.

jcc
Not sure if it helps, but this link suggests that the DELIMITER doesn't work from the php interfaces.

http://stackoverflow.com/questions/14569528/execute-mysql-create-function-statement-with-php

FWIW

nicholas
Akeeba Staff
Manager
If I remove the lines adding the DELIMITER we're back at the state we were on May 15th when you filed your ticket. Of course that was the state that used to work for everyone else (I guess? Nobody reported otherwise) for the last 2+ years.

Your guess is as good as mine.

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!

jcc
I think the (original) issue has to do with whether the function is already defined in the target database. To test, I reverted to 3.7.7, created a new backup and restored to unique database names. That correctly creates the functions. Restore the backup again using the same database and it fails on the first function definition.

If I create the same function twice in the same database using the mysql client, I get an expected exception - "ERROR 1304 (42000): FUNCTION fn_get_pog_configuration already exists". If I try to create a table twice in the same database, I get an expected exception - "ERROR 1050 (42S01): Table 'pog_configuration' already exists".

I don't understand is why the create table statements in the restore seem to replace the table where the create function statements fail. Are you trapping the table 'already exists' exceptions and not the one for the functions?

nicholas
Akeeba Staff
Manager
When you select the Drop option then every procedure/function/trigger is being DROPed before attempting to create it afresh.

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!

jcc
I swear I was using DROP, but now I can't reproduce. Sorry to waste your time!

nicholas
Akeeba Staff
Manager
No problem :)

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!

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!