Skip to navigation
Basic bash script to keep a wordpress mysql database synced between a production and a docker server
27.09.19
as wordpress is saving the full path urls into your database, the url needs to be changed on another deployment. this script helps to update, search and replace the urls domains between your dev docker station and your production servers #!/bin/bash ##################################################### # set here your settings: prod_server_ip=fe80::bc4d:b7ff:fec5:4a38 prod=https://foo.bar.com docker=http://127.0.0.1 db_server=db_docker_name db_user=foosql1 db_pass=barbar db_name=foosql1 ###################################################### ip="$( ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/' )" if [ $ip == $prod_server_ip ] then echo "...this is the production server" _from=$docker _to=$prod else echo "...this is the local server" _from=$prod _to=$docker fi #if you set from to parameter if [ -z $1 ] then from=$_from else from="${1}" fi if [ -z $2 ] then to=$_to else to="${2}" fi #do the job: echo "...import from init" docker run -i --rm --net=host salamander1/mysql -h 127.0.0.1 --user=$db_user -p$db_pass $db_name < init/$db_name.sql echo "...replace wordpress" docker run --add-host $db_server:127.0.0.1 --net=host -v "$(dirname "$(pwd)")":`pwd` -w `pwd` -i --rm wordpress:cli wp search-replace "${from}" "${to}" --skip-columns=guid
https://developer.wordpress.org/cli/commands/search-replace/
Reply
Anonymous
Information Epoch 1757985431
Make every program a filter.
Home
Notebook
Contact us