Skip to content

Instantly share code, notes, and snippets.

@lucasstark
Last active January 19, 2024 14:36
Show Gist options
  • Save lucasstark/a256063e1583630bf0a964e4f4d0b3ea to your computer and use it in GitHub Desktop.
Save lucasstark/a256063e1583630bf0a964e4f4d0b3ea to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the Homebrew installation prefix
BREW_PREFIX=$(brew --prefix)
# Homebrew MySQL client tools path
MYSQL_CLIENT_PATH="${BREW_PREFIX}/bin"
echo "MySQL Client Tools: $MYSQL_CLIENT_PATH"
# Rsync to copy the WordPress site
rsync -avz lustark@westland.wccnet.edu:/var/www/html/intranet .
# Function to extract DB details from wp-config.php
extract_db_config() {
local key=$1
local line=$(grep -E "define\(\s*['\"]$key['\"]," intranet/wp-config.php)
echo $line | awk -F"'" '{print $4}'
}
# Extract DB details
DB_NAME=$(extract_db_config 'DB_NAME')
DB_USER=$(extract_db_config 'DB_USER')
DB_PASSWORD=$(extract_db_config 'DB_PASSWORD')
DB_HOST=$(extract_db_config 'DB_HOST')
# Current date in YYYY-mm-dd format
DATE=$(date +%F)
# Local directory to save the database dump
LOCAL_DB_DIR="./intranetdb-$DATE"
mkdir -p $LOCAL_DB_DIR
# Use mysqldump to export the database
${MYSQL_CLIENT_PATH}/mysqldump -u "$DB_USER" -p"$DB_PASSWORD" -h "$DB_HOST" "$DB_NAME" > $LOCAL_DB_DIR/prod.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment