Created
October 8, 2012 16:12
-
-
Save cyberhobo/3853334 to your computer and use it in GitHub Desktop.
Bash alias for mysqldump using credentials from a wp-config.php file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# one argument: the directory of a wp-config.php file | |
wpconfig=$1/wp-config.php | |
if [ ! -f "$wpconfig" ]; then | |
echo "$wpconfig not found." | |
exit | |
fi | |
db=`sed -n -e "s/^define( *'DB_NAME', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
if [ -z $db ]; then | |
echo "Database name not found in $wpconfig." | |
exit | |
fi | |
user=`sed -n -e "s/^define( *'DB_USER', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
if [ -z $db ]; then | |
echo "Database user not found in $wpconfig." | |
exit | |
fi | |
pw=`sed -n -e "s/^define( *'DB_PASSWORD', *'\([^']*\)'.*/\1/p" < $wpconfig` | |
if [ -z $db ]; then | |
echo "Databaseabase credentials not found in $wpconfig." | |
exit | |
fi | |
mysqldump --user=$user --password=$pw $db |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Want
--password="$pw"
if your password contains spaces :-)