All Collections
Linux / SSH / Bash
Mass find all WordPress installs and backup their databases
Mass find all WordPress installs and backup their databases

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.

Justin Catello avatar
Written by Justin Catello
Updated over a week ago
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
Did this answer your question?