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.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

17 Responses to Scripting mysql database backups on phpMyadmin with CURL

  1. Robert says:

    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. @Robert, you may wish to check the new version if it works for you now.

  3. Matt says:

    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!

  4. marcoc assisa says:

    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

  5. JimmyJam says:

    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!

  6. obones says:

    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

  7. niknah says:

    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)

  8. thomas says:

    great script! now my headache are over…

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

  9. Thanks @JimmyJam. I’ve updated the version in SVN

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

  11. @thomas: Dunno… but any patch would be welcome ;)

  12. FYI, I’ve updated the script in SVN to adjust to a more recent phpmyadmin for which it would no longer work.

  13. Martin says:

    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

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

  15. klara says:

    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\”"

  16. klara says:

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

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

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>