Sometimes, you can only access your MySQL database with phpMyadmin (the previous tool I blogged about won’t be helpful, then). But you may wish to backup the database on a regular way.
PhpMyadmin allows you to backup the database, but you may like to do it in an unattended way.
I’ve written a shell-script which will use CURL to do so.
I couldn’t find any such script… so I hope I didn’t reinvent the wheel 😉
Update 2008/04/15 : I have made some modifications to the script, and it is now in SVN. You may grab a copy from the picoforge project’s websvn.
Ever come across:
Missing parameter: what
Missing parameter: export_type
I get it even using your script. No matter what I try, export.php complains exactly the same but it works fine from a browser.
@Robert, you may wish to check the new version if it works for you now.
Thank you very much!
I have been using wget to accomplish the same thing for a few months but after my hosting provider upgrade phpMyAdmin and mySQL, my script no longer worked and would give “missing parameter” errors like Robert experienced. I spent many hours trying to update my script and searching the internet for a solution. Your script worked like a charm and saved my more time wasted!
thank you very much, Olivier!!!
btw your blog is very nice
I dropped a note linking to your website here: http://wiki.cihar.com/pma/FAQ_6.4 where an older, no more working script is suggested.
Hope you’ll appreciate
marco
Very useful indeed.
I tried to run this script from my Windows system + Cygwin. I had to modify this:
result=$(tempfile)
to
result=$(mktemp)
Now it works as advertised!
Hi,
First of all, many thanks for this script, it looks very promising. I also had to change tempfile for mktemp, but it does not solve all my problems
I must be doing something wrong as I do not get any dump file, but an error message from mv complaining that it cannot find the export.php file.
Any idea as to what could be the source of this?
Thanks
Olivier
I too had my own script and that was working but it stopped working recently with a “missing parameter” problem.
This script works great, thanks!
The only thing I had to change was to move the login entry_params to the curl statement(I’m not using basicauth), like…
curl -d “pma_username=$user&pma_password=$password&server=1” -s -k -D curl.headers -L -c cookies.txt $server/index.php >$result
Don’t know why, it wouldn’t login with entry_params as a variable, using bash 3.2.39 (ubuntu 8.10)
great script! now my headache are over…
is there any easy way to exclude tables from the backup?
Thanks @JimmyJam. I’ve updated the version in SVN
@niknah : did you notice I had a condition on the value of the auth variable (=basicauth by default), to support both auth methods ?
@thomas: Dunno… but any patch would be welcome 😉
FYI, I’ve updated the script in SVN to adjust to a more recent phpmyadmin for which it would no longer work.
Got the same as Robert 4 years ago:
Missing parameter: what
Missing parameter: export_type
Using phpmyadmin 2.9.1.1-3 (debian) and [curl-backup-phpmyadmin.sh] – Rev 10
To extract the token I needed one more grep to get only one line to write into $token:
old:
token=$(grep link $result | grep token | sed "s/^.*token=//" | sed "s/&.*//")
new:
token=$(grep link $result | grep 'phpmyadmin.css.php' | grep token | sed "s/^.*token=//" | sed "s/&.*//" )
Now it is easy to get a backup of my database.
Thanks Olivier,
Martin
@Martin : thanks. I’ve integrated your suggestion in the SVN version.
I’ve also updated it to work with PhpMyAdmin 3.4.5.
Hope this helps.
to get the script working for certain hosting providers, the following modification was needed:
# Then we can reuse these cookies and tokens to prepare a POST for actual login
entry_params=”-d \”phpMyAdmin=$cookie&phpMyAdmin=$cookie&pma_username=$user&pma_password=$password&pma_servername=$remote_host&server=1&phpMyAdmin=$cookie&lang=en-utf-8&convcharset=utf-8&collation_connection=utf8_general_ci&token=$token&input_go=Go\””
The update above did not catch all changes correctly, hopefully this does.
In essential: to the login entry,
pma_servername=$remote_host
has to be added:# Then we can reuse these cookies and tokens to prepare a POST for actual login
entry_params="-d \"phpMyAdmin=$cookie&phpMyAdmin=$cookie&pma_username=$user&pma_password=$password&pma_servername=$remote_host&server=1&phpMyAdmin=$cookie&lang=en-utf-8&convcharset=utf-8&collation_connection=utf8_general_ci&token=$token&input_go=Go\""
https://github.com/michaelfraser/remote-backup seems to be very much like what I propose… haven’t had the time to check more (via marco cassisa)
FWIW, I’ve played with a similar tool to connect to an application behind CAS, which allows to use httrack to copy a local backup of contents (works with Sympa for list’s Shared document folders) : https://gist.github.com/olberger/4327fb94ca557e4ba58c0314d9c6f740