Ok so my web host doesn’t allow the use of INTO OUTFILE / mysql dump and I am required to develop a backup script.
How would I go about doing this in PHP. Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are some nifty and still simple backup scripts out there; the one from PHPMyAdmin is probably a very good one because well tested, the problem is to extract that from the whole package to be able to call it automatically.
For the exact same task I developed my own small script, which iterates over all tables in a database and sends the contents in a bzipped sql file (meaning that it can easily be imported again if the backup should be needed).
Because it is so simple, this script of course also has its limitations, as pointed out in the comment below: It only backs up the table content. Not even the table structure is preserved, the assumption here is that the table structure changes very seldomly and also could be easily reconstructed if needed. But if your software changes the schema rather often and automatically, or if it uses functions or views, you might have to look for a more advanced script!
So far for the “disclaimers”, here we go with the simple script:
I guess it still could need a few improvements (security e.g.), but it serves the purpose quite well. To use it, upload it to your webspace, let’s say as ‘backup-db.php’ (preferredly in some hidden folder), and call it like this
You of course first have to adapt the values in brackets <>. Feel free to use and adapt it; should you make any improvements, I’d be very glad to hear about it!