Skip to content

Instantly share code, notes, and snippets.

@leogdion
Last active January 2, 2016 18:29
Show Gist options
  • Save leogdion/8343509 to your computer and use it in GitHub Desktop.
Save leogdion/8343509 to your computer and use it in GitHub Desktop.
#!/bin/bash
function var() {
eval $2=`grep -Po "define\('$3',\s*'(\K[^']+)" $1 | head -n 1`
}
wp_config=$1
base_dir=$2
date_prefix=$(date -u +"%y%m%d%H")
var $wp_config 'db_name' 'DB_NAME'
var $wp_config 'db_user' 'DB_USER'
var $wp_config 'db_password' 'DB_PASSWORD'
var $wp_config 'db_host' 'DB_HOST'
host_name=`dig +short -x ${db_host} | sed 's/.$//'`
if [ -z "$host_name"]
then
echo 'no host name'
host_name=db_host
fi
dir_path=${base_dir}/${db_name}/${host_name}
file_path=${dir_path}/${date_prefix}.${db_host}.sql.gz
mkdir -p ${dir_path}
mysqldump ${db_name} -u ${db_user} -p${db_password} -h ${db_host} --single-transaction | gzip -9 > ${file_path}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment