Bash scripting that extracts production WordPress websites and updates their local versions in my computer. Designed to run on a MacBook.
- Requires bash 5
- Requires sshpass if you choose to use ssh passwords instead of key files.
- Download exfil.sh and this README.md file
- Create a configuration file
example.conf
for each local and production website pair. Use the sample file contents below. - Change the email address on line 28 to your email address. Consider using a command like
sed -i '' -e "s|[email protected]|[email protected]|g" exfil.sh
- Navigate to the directory that contains
exfil.sh
and your configuration files in Terminal - Type
bash exfil.sh
orbash exfil.sh example
to skip the prompt asking which configuration file should be loaded - Enter
q
at any prompt to abort the program
Create a file in the same directory as exfil.sh
named example.conf
and change all the example values to match your local and production environments. An explanation of each variable in the config file can be found below the sample.
declare -A SITE=(
[ssh_user_at_host]="[email protected]"
[ssh_port]=12345
[ssh_password]=""
[ssh_remote_key_file]="privatekeyfilename"
[production_mysql_database]="database_name"
[production_mysql_user]="user"
[production_mysql_password]="password"
[local_mysql_database]="database_name"
[local_mysql_user]="user"
[local_mysql_password]="password"
[production_domain]="://example.xyz"
[local_domain]="://example.test"
[production_path]="path/public_html/example.xyz/"
[local_path]="/Users/user/Sites/example/"
[production_root_path]="path/"
[script_after]=""
)
export SSHPASS="${SITE[ssh_password]}"
- ssh_user_at_host The SSH user name and host separated by @. [email protected]
- ssh_port The port number where SSH is available. 58134
- ssh_password The SSH user password. See SSH Authentication notes below. o0o00oo0oo00o0o
- ssh_remote_key_file The name of a file containing an SSH private key. SSH Authentication notes below. example
- production_mysql_database The name of the database on the remote server. breakfastco
- production_mysql_user The name of the user with permission to query the remote database. user_name
- production_mysql_password The remote database user's password. 66g6gggg6g66g
- local_mysql_database The name of the database on the local server. wp_breakfastco
- local_mysql_user The name of the user with permission to query the local database. root
- local_mysql_password The local database user's password root
- production_domain The remote site's domain including subdomain and starting with
://
. Used to change all URLs stored in the database. A version that begins with ://www. will also be replaced. ://example.com - local_domain The local site's domain including subdomain. A version beginning with
://www.
will also replace versions of production_domain beginning with://www.
. ://example.test - production_path Full path to the WordPress root folder on the remote server. path/public_html/example.com/
- local_path Full path to the WordPress root folder on the local server. /Users/user/Sites/example/
- production_root_path Full path to the user's home directory we land in when connecting to the server via SSH. Sometimes does not like a preceding slash. path/
- script_after Optional. Script to run after the local copy of the site is updated. wp user create corey [email protected] --role=administrator
This script supports both password and public key SSH authentication. To use a password, provide it in ssh_password
. Register an SSH private key file using a command like ssh-add /Users/{user-name}/{...}/privatekeyfilename
before running exfil, and provide the private key file name in ssh_remote_key_file
.
- Fixed Fixes a bug when downloading "All of wp-content"
- Added Replaces Gravity Forms Cloudflare Turnstile add-on site key and secret keys with dummy values that will always pass.
- Fixed Changes all multi file transfers to use rsync instead of scp.
- Fixed Adds a warning when sshpass is being used.
- Fixed Prevents sshpass from being used when no password is found in conf file.
- Fixed Do not activate the use-mailhog plugin before the folder is renamed.
- Fixed Only replaces www. versions of the production domain if the production domain does not already start with www.
- Fixed Adds -O parameter to all scp calls so the script works on WP Engine.
- Changed Adds the --report-changed-only parameter to all wp search-replace calls to shrink the output.
- Added Checks one level above the current directory for .conf files. I have moved this script into a directory to simplify my copy of the repo.
- Fixed Adds --no-tablespaces to the mysqldump commands. Rocket.net requires it.
- Changed Stops installing and activating stop-emails. Replaces it with use-mailhog.
- Added Now replaces versions of each domain that begin with
://www.
in addition to the provided domains. - Changed Changes my email address in the code to a Github anonymized address.
- Added Now detects a
$table_prefix
mismatch and edits the localwp-config.php
to match remote
- Added Now checks for the WP Engine mysql.sql file when
mysqldump
fails
- Added Adds a .conf file variable
script_after
to hold scripting that will be run in the local site's directory after the local site is updated.
- Added Accepts
q
at any prompt to abort the program. - Added If the Gravity Forms plugin is active, exfil now activates or installs and activates the Power Boost for Gravity Forms plugin.
- Added Deactivates SiteGround's SG Optimizer plugin if it is active.
- Added Installs and activates the Stop Emails plugin if it is not found to be active.
- Fixed Specify a full path when saving the .sql backup file on the server so we can predict where to find it.
- Changed Asks whether to delete the downloaded .sql file after importing it before starting the import. This puts all questions at the beginning, and lets the program exit instead of sitting on this question if the user turns their attention away while the import is running.
- Fixed Now checks that the specified .conf file exists before trying to load it. If the file does not exist, delivers an error message and aborts the program.
- Added Adds the GPL 2 license file
- Added Adds instructions to change the email address used to overwrite the admin email
- Changed Changes the file download feature to present a menu with five choices instead of just yes/no on the whole wp-content folder
- Changed Now suppresses the server's welcome message during ssh connections for cleaner output
- Changed Skips loading plugins and themes when running WP CLI commands for cleaner output
- Changed Downloading the wp-content folder is now optional
- Fixed The delete local .sql files feature now works
- Added Now downloads the
wp-content
directory
- Fixed Edits all
ssh
commands to add option-o StrictHostKeyChecking=no
. This prevents the promptAre you sure you want to continue connecting (yes/no)?
from disrupting the first call tossh
. I had been manually connecting withssh
prior to using this script to answer yes to the prompt, and this version eliminates that step by always trusting the host keys.
First version that supports both SSH password and public key authentication methods.
- Added Adds this change log to README.md
- Removed Removes duplicate credentials in configuration files