Scripting mysql database backups on phpMyadmin with CURL

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.

18 thoughts on “Scripting mysql database backups on phpMyadmin with CURL”

  1. 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.

  2. 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!

  3. 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

  4. 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!

  5. 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

  6. 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)

  7. great script! now my headache are over…

    is there any easy way to exclude tables from the backup?

  8. @niknah : did you notice I had a condition on the value of the auth variable (=basicauth by default), to support both auth methods ?

  9. 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

  10. @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.

  11. 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\””

  12. 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\""

Leave a Reply

Your email address will not be published. Required fields are marked *