Skip to main content

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 month ago

In this article, we will demonstrate how to efficiently find all WordPress installations on your server and back up their databases. Using these below commands, you can automatically detect each WordPress site, extract the database name from the configuration file, and create compressed backups of the databases. This method helps streamline database backups for multiple WordPress sites, saving time and effort.

Please run this script in the directory where you want to search for WordPress installations and back up their databases, including all its subdirectories.

Run this as one single command:

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

Once the above command is run, it will output the following, indicating that all WordPress databases have been backed up successfully to the specified backup folder(/backup/wpdb).



Congratulations! You've successfully found all WordPress installations and backed up their databases.

If you have any questions, please don’t hesitate to contact our team via live chat.

For technical inquiries, please feel free to reach our support team by emailing support@bigscoots.com from your registered email or by submitting a support ticket.

Did this answer your question?