Skip to content

Instantly share code, notes, and snippets.

@mjtiempo
Created September 18, 2019 01:25
Show Gist options
  • Save mjtiempo/d40d51a09977428954297262c181b8d3 to your computer and use it in GitHub Desktop.
Save mjtiempo/d40d51a09977428954297262c181b8d3 to your computer and use it in GitHub Desktop.
#!/bin/bash
#read db credentials from wp-config.php
source <(php -r 'require("wp-config.php"); echo("DB_NAME=".DB_NAME."; DB_USER=".DB_USER."; DB_PASSWORD=".DB_PASSWORD."; TABLE_PREFIX=".$table_prefix); ')
#dump wp db on wpdb_backup_$DB_NAME.sql
mysqldump --user $DB_USER --password="$DB_PASSWORD" $DB_NAME > wpdb_backup_$DB_NAME.sql
#find and replace $table_prefix
sed -i 's/$TABLE_PREFIX/wp_/g' wpdb_backup_$DB_NAME.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment