I want a PHP based solution to backup database (only data and not code) of a remote server and download the file. I know that Shell based solutions are better for doing such things (running a shell script on local system and connecting through SSH to remote system) but it is a requirement to have a PHP based solution where knowing a URL and having database credentials is enough for a non-techie to take backups. The PHP script can be uploaded to the remote server and executed.
Following are the features I want:-
- Should have support for InnoDb engine at least - foreign key constraints should be exported. No harm if it supports all other engines.
Should work on all servers, in the presence of the maximum possible amount of restrictions (I know about a few restrictions like
safe_mode
enabled,exec()
,system()
functions disabled etc.). I want a very general purpose solution which is guaranteed to work anywhere.Process should be password authenticated (asks for database credentials).
Now, I am breaking down things and starting from the very basics. Following are my assumptions of things so far and some questions:-
I am not sure if system functions like
exec
,system
etc. can be completely disabled in shared hosting servers or not. If they are disabled such that they cannot be overridden, then themysqldump
based solution given here will not work universally.
Question - If however onlysafe_mode
is on such that system functions can execute on files present insidesafe_mode_exec_dir
, will the solution work securely?I asked a question regarding security risks of doing this using PHP and understood that the backup file should never be created (I assume, in case of a
mysqldump
based solution, backup file needs to be created first before downloading) in the webspace. So, the solution should not need the backup files to be created there (no problem if creates in other locations).
Question - But, will shared hosting providers allow this?I checked out various general-purpose user contributed PHP classes like phpmysqldump etc. and did not find the usage of
mysqldump
based solution using system commands there to take backup. They do things likeSHOW CREATE TABLE
etc. to get all the table creation, data insertion queries and then download those things without actually saving it as a file (so no security risk).
Question - Am I correct to conclude that they do all these things without doing a simplemysqldump
as given in the solution in the first point because this cannot be a general purpose and secure solution?
Question - Also, I read that there aren't any good ones which work well. I personally used only this phpmysqldump and it gives me mysql errors when I try to restore a database with the backup created. The queries in the dump file also look somewhat different from those created by PhpMyAdmin's export module. I also checked a few other free user contributed PHP classes. It looks like most of them do not support InnoDb support and so foriegn key constraints, if present in the database are not present in the export.
Question - The export functionality of PhpMyAdmin itself, if present separately could be the solution for me, I guess. Does anybody know of any stable library like this one?