-
-
Save retlehs/aa47003249623e52b95a3fcd6f69b8fb to your computer and use it in GitHub Desktop.
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response | |
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
wp @development db reset --yes && | |
wp @production db export - > sql-dump-production.sql && | |
wp @development db import sql-dump-production.sql && | |
wp @development search-replace https://example.com https://example.dev | |
fi |
path: web/wp | |
@production: | |
ssh: [email protected]/srv/www/example.com/current | |
@development: | |
ssh: [email protected]/srv/www/example.com/current |
Ok I'm done ! :D it is great script! Here's my version
#!/usr/bin/env bash
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
wp @staging db reset --yes &&
wp db export sql-dump-dev.sql --add-drop-table &&
wp @staging db import - < sql-dump-dev.sql &&
wp @staging search-replace http://strefatradera.l http://strefatradera.ufff.pl
fi
I've always been a bit fuzzy on this, why use the search-replace on the sites url when it's much easier to just set WP_HOME and WP_SITEURL in the wp config
I would guess because the WordPress editor inserts the site URL when adding internal links and img tags. So you have to change those strings in the post_content field for every post.
Those URLs also exist in the wp_options table, which is from where all the WordPress core functions get them (I'm mostly sure). You could use the wp-config constants in your own themes and plugins, but other plugin devs will still use them. ..Although I suppose you could hook into those functions and switch them to pull from the constants. But you'd still have the post_content problem.
I don't know why I get Error: Import file missing: sql-dump-production.sql... It seems the SQL file does not get into @development server for me :/ If I run
wp @development db import sql-dump-production.sql --debug
I get:How to debug it more?
I use newest Wordpress and wp-cli