Last active
January 19, 2024 14:36
-
-
Save lucasstark/a256063e1583630bf0a964e4f4d0b3ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]:/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