Skip to content

Commit

Permalink
Bumps version to 1.1.1. Fixes the delete local .sql file feature that…
Browse files Browse the repository at this point in the history
… had never previously worked. Downloading the wp-content folder is now optional because it uses scp instead of rsync and takes forever. Suppresses the server welcome message. Attempts to suppress output when using WP CLI commands.
  • Loading branch information
csalzano committed Aug 7, 2020
1 parent b95813a commit c3ed40e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ This script supports both password and public key SSH authentication. To use a p

## changelog

### 1.1.1

- __Changed__ Now suppresses the server's welcome message during ssh connections for cleaner output
- __Changed__ Skips loading plugins and themes when running [WP CLI](https://wp-cli.org/) commands for cleaner output
- __Changed__ Downloading the wp-content folder is now optional
- __Fixed__ The delete local .sql files feature now works

### 1.1.0

- __Added__ Now downloads the `wp-content` directory
Expand Down
41 changes: 28 additions & 13 deletions exfil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# is a program that extracts production WordPress databases and updates
# their local versions in my computer
#
# version 1.1.0
# version 1.1.1
#


Expand Down Expand Up @@ -46,11 +46,14 @@ source "${site_name}.conf"

# create the database backup on the server
FILE="${SITE[local_mysql_database]}.sql"
if [ -z "${SITE[ssh_remote_key_file]}" ]
if [ -z "${SITE[ssh_remote_key_file]}" ] # Test if the lengh of STRING is zero (ie it is empty).
then
echo "Exporting database..."

sshpass -e ssh -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" << EOF
# -o delivers option StrictHostKeyChecking=no to avoid a yes/no question and blindly trust the host's ssh key
# -q suppresses the server welcome message
# -p specifies the port number
sshpass -e ssh -q -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" << EOF
mysqldump --user="${SITE[production_mysql_user]}" --password="${SITE[production_mysql_password]}" "${SITE[production_mysql_database]}" > "${FILE}"
EOF

Expand All @@ -62,17 +65,23 @@ EOF
echo "Deleting .sql file from server..."
sshpass -e ssh -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" "rm -f ${SITE[production_root_path]}${FILE}"

# download the wp-content folder
echo "Downloading the wp-content folder..."
sshpass -p "${SITE[ssh_password]}" scp -r -P "${SITE[ssh_port]}" "${SITE[ssh_user_at_host]}":"${SITE[production_path]}wp-content" "${SITE[local_path]}"
# maybe download the wp-content folder
echo "Download the wp-content folder? (y/n)"
read download_wp_content
if [ "y" == "$download_wp_content" ]
then
echo "Downloading the wp-content folder..."
sshpass -p "${SITE[ssh_password]}" scp -r -P "${SITE[ssh_port]}" "${SITE[ssh_user_at_host]}":"${SITE[production_path]}wp-content" "${SITE[local_path]}"
fi


else
# can't automate this unless we track the password on the key
# ssh-add /Users/{user-name}/{...}/"${SITE[ssh_remote_key_file]}"

echo "Exporting database..."

ssh -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" << EEOF
ssh -q -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" << EEOF
mysqldump --user="${SITE[production_mysql_user]}" --password="${SITE[production_mysql_password]}" "${SITE[production_mysql_database]}" > "${FILE}"
EEOF

Expand All @@ -84,9 +93,14 @@ EEOF
echo "Deleting .sql file from server..."
ssh -o StrictHostKeyChecking=no "${SITE[ssh_user_at_host]}" -p "${SITE[ssh_port]}" "rm -f ${SITE[production_root_path]}${FILE}"

# download the wp-content folder
echo "Downloading the wp-content folder..."
scp -r -P "${SITE[ssh_port]}" "${SITE[ssh_user_at_host]}":"${SITE[production_path]}wp-content" "${SITE[local_path]}"
# maybe download the wp-content folder
echo "Download the wp-content folder? (y/n)"
read download_wp_content
if [ "y" == "$download_wp_content" ]
then
echo "Downloading the wp-content folder..."
scp -r -P "${SITE[ssh_port]}" "${SITE[ssh_user_at_host]}":"${SITE[production_path]}wp-content" "${SITE[local_path]}"
fi
fi

# if local file does not exist, do not continue
Expand Down Expand Up @@ -136,16 +150,17 @@ COMMIT;
EOFMYSQL

# Use wp-cli to change admin email to me
wp option update admin_email '[email protected]'
wp option update new_admin_email '[email protected]'
# Do not load plugins or themes to avoid debug message output
wp option update admin_email '[email protected]' --skip-plugins --skip-themes
wp option update new_admin_email '[email protected]' --skip-plugins --skip-themes

# Move to the site folder before deletes
cd "${SITE[local_path]}"

# Delete the local .sql files
echo "Delete local .sql files? (y/n)"
read delete_sql_files
if [ "y" = delete_sql_files ]
if [ "y" == "$delete_sql_files" ]
then
rm -f "${SITE[local_path]}${FILE}"
rm -f "${SITE[local_path]}${FILE}.backup.txt"
Expand Down

0 comments on commit c3ed40e

Please sign in to comment.