Skip to navigation
Bash file to export a WordPress database to init/foo.sql.gz
11.03.21
you wanna easy export a wordpress mysql database without wasting your time collecting user and password of the site. in a folder inside your wordpress files create a file like /dockers/ex.sh : #!/bin/bash #note: the value of the 3 variable cannot include characters ( ) _DB_NAME="$(grep -oE "\DB_NAME',.*;" ../wp-config.php | tail -1 | sed "s/DB_NAME',//g;s/'//g" | sed "s/DB_NAME',//g;s/)//g" | sed "s/DB_NAME',//g;s/;//g" | sed "s/DB_USER',//g;s/ //g") " _DB_USER="$(grep -oE "\DB_USER',.*;" ../wp-config.php | tail -1 | sed "s/DB_USER',//g;s/'//g" | sed "s/DB_USER',//g;s/)//g" | sed "s/DB_USER',//g;s/;//g" | sed "s/DB_USER',//g;s/ //g") " _DB_PASSWORD="$(grep -oE "\DB_PASSWORD',.*;" ../wp-config.php | tail -1 | sed "s/DB_PASSWORD',//g;s/'//g" | sed "s/DB_PASSWORD',//g;s/)//g" | sed "s/DB_PASSWORD',//g;s/;//g" | sed "s/DB_PASSWORD',//g;s/ //g") " DB_NAME="${_DB_NAME//[[:blank:]]/}" DB_USER="${_DB_USER//[[:blank:]]/}" DB_PASSWORD="${_DB_PASSWORD=//[[:blank:]]/}" docker run -i --rm --net=host salamander1/mysqldump --verbose -h 127.0.0.1 -u "${DB_NAME//[[:blank:]]/}" -p"${DB_PASSWORD//[[:blank:]]/}" "${DB_NAME//[[:blank:]]/}" | gzip > "init/${DB_NAME//[[:blank:]]/}.sql.gz" echo "DB: " $DB_NAME echo "DB USER: " $DB_USER echo "DB PASSWORD: " $DB_PASSWORD echo "DB exported to: " "init/${DB_NAME//[[:blank:]]/}.sql.gz"
https://hub.docker.com/r/salamander1/mysqldump/
Reply
Anonymous
Information Epoch 1745875144
You can always add complexity.
Home
Notebook
Contact us