I'm using the following script to attempt to download an SQL export from a phpMyAdmin installation (adapted from this Stackoverflow question)
read -p "Username: " USERNAME
read -p "Password: " PASSWORD
ADMIN_URL='https://example.com/phpmyadmin'
COOKIEJAR='/tmp/phpmyadmin_cookie'
token=$(
wget -qO- \
--http-user="$USERNAME" \
--http-password="$PASSWORD" \
--save-cookies "$COOKIEJAR" \
--keep-session-cookies \
"$ADMIN_URL" \
| egrep -o 'token=[[:xdigit:]]+' | head -1
)
post_data="$token&what=sql&export_type=server"
wget -O export.sql \
--save-headers \
--http-user="$USERNAME" \
--http-password="$PASSWORD" \
--load-cookies "$COOKIEJAR" \
--post-data "$post_data" \
"$ADMIN_URL/export.php"
rm "$COOKIEJAR"
Unfortunately, phpMyAdmin 4.7.9 responds with a Server 500 error:
--2018-03-21 15:27:35-- https://woosh5.nl/phpmyadmin/export.php
Resolving woosh5.nl (woosh5.nl)... 37.97.205.130, 2a01:7c8:aac3:7::11
Connecting to woosh5.nl (woosh5.nl)|37.97.205.130|:443... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="phpMyAdmin localhost"
Reusing existing connection to woosh5.nl:443.
HTTP request sent, awaiting response... 500 Internal Server Error
2018-03-21 15:27:35 ERROR 500: Internal Server Error.
I'm quite certain the authentication succeeds, so there must be something wrong with the POST parameters I'm sending.
How can I automate the downloading of SQL dumps from phpMyAdmin?