HomeHome ImpressionImpressions IdiomsIdioms DeliciousDelicious Self-ImageSelf-Image ImpermanenceImpermanence Happy ShoppingHappy Shopping Do It YourselfDo It Yourself Street ArtStreet Art Tibetan ArtTibetan Art Magic NumberMagic Number Bread and CircusesBread and Circuses FeedbackFeedback ProjectProject
Export Database Script Through PhpMyAdmin - Do It Yourself No. 43 Open Source Freifeld - Magic Number No. 27 Father And Son - Self-Image No. 43 Portrait By Mother - Self-Image No. 42 JavaScript Location Search/Hash-Params To Object-Map - Magic Number No. 26 Advent Calendar - Happy Shopping No. 34

Export Database Script Through PhpMyAdmin - Do It Yourself No. 43

Thursday 2012-01-05 00:12:46   [feedback]   [link]

There are some wget and curl examples on how to export a dump of a database of a remote phpMyAdmin installation, none of which I could manage to get running. Two days of fiddling myself finally resulted in this working script tested against phpMyAdmin 3.4.3.2, the highlighted lines need adjusting to ones own needs:

#! /bin/sh
USER=mylogin
PASSWORD=mypassword
DBNAME=mydatabase
MYPHP=https://the_host/phpMyAdmin/
wget -q --auth-no-challenge -O index.html --cookies=on --load-cookies=cookie.txt --keep-session-cookies --save-cookies=cookie.txt --user=$USER --password=$PASSWORD $MYPHP
token=`cat index.html|grep "token ="|sed "s/.*= '//g"|sed "s/'.*//g"`
EXPORTURL=${MYPHP}export.php
POST="'collation_connection=utf8_general_ci&token=$token&export_type=server&export_method=quick&quick_or_custom=custom&db_select%5B%5D=$DBNAME&output_format=sendit&filename_template=%40SERVER%40&remember_template=on&charset_of_file=utf-8&compression=gzip&what=sql&codegen_structure_or_data=data&codegen_format=0&csv_separator=%2C&csv_enclosed=%22&csv_escaped=%5C&csv_terminated=AUTO&csv_null=NULL&csv_structure_or_data=data&excel_null=NULL&excel_edition=win&excel_structure_or_data=data&htmlexcel_null=&htmlexcel_data=&htmlword_structure_or_data=structure_and_data&htmlword_null=NULL&json_structure_or_data=data&latex_caption=something&latex_structure_or_data=structure_and_data&latex_structure_caption=Structure+of+table+%40TABLE%40&latex_structure_continued_caption=Structure+of+table+%40TABLE%40+%28continued%29&latex_structure_label=tab%3A%40TABLE%40-structure&latex_relation=something&latex_comments=something&latex_mime=something&latex_columns=something&latex_data_caption=Content+of+table+%40TABLE%40&latex_data_continued_caption=Content+of+table+%40TABLE%40+%28continued%29&latex_data_label=tab%3A%40TABLE%40-data&latex_null=%5Ctextit%7BNULL%7D&mediawiki_structure_or_data=data&ods_null=NULL&ods_structure_or_data=data&odt_structure_or_data=structure_and_data&odt_relation=something&odt_comments=something&odt_mime=something&odt_columns=something&odt_null=NULL&pdf_report_title=&pdf_structure_or_data=data&php_array_structure_or_data=data&sql_include_comments=something&sql_header_comment=&sql_compatibility=NONE&sql_structure_or_data=structure_and_data&sql_procedure_function=something&sql_create_table_statements=something&sql_if_not_exists=something&sql_auto_increment=something&sql_backquotes=something&sql_type=INSERT&sql_insert_syntax=both&sql_max_query_size=50000&sql_hex_for_blob=something&sql_utc_time=something&texytext_structure_or_data=structure_and_data&texytext_null=NULL&xls_null=NULL&xls_structure_or_data=data&xlsx_null=NULL&xlsx_structure_or_data=data&yaml_structure_or_data=d'"
OUTPUT="$1.sql.gz"
wget --auth-no-challenge --output-document $OUTPUT --user=$USER --password=$PASSWORD --referer=$LOGINURL --cookies=on --load-cookies=cookie.txt --keep-session-cookies --save-cookies=cookie.txt --post-data $POST $EXPORTURL
rm index.html cookie.txt
The --auth-no-challenge is of big importance, as each HTTP/1.1 401 Unauthorized destroys the cookie needed for a successful export. Otherwise a
export.php: Missing parameter: what
export.php: Missing parameter: export_type
is returned as a general error indicating that no post-parameters where accepted because cookie/token verification failed.


Feedback


feedback chooser