for wpinstall in $(find "$(pwd)"/ -type f -name wp-config.php | sed 's/wp-config.php//g')
do
echo "$wpinstall"
dbname=$(grep DB_NAME "$wpinstall"/wp-config.php | grep -v WP_CACHE_KEY_SALT | cut -d \' -f 4)
echo "Database Name: $dbname"
echo "Creating backup folder /backup/wpdb"
mkdir -p /backup/wpdb
echo "Backing up databases to /backup/wpdb"
/usr/bin/mysqldump "$dbname" | gzip > /backup/wpdb/"$dbname".sql.gz
done
This one liner will search for all wp-config.php scripts in the parent directory, pull the database name and create a backup of it.
Written by Justin Catello
Updated over 7 years ago