Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Bash script to dump a WordPress database, pulling settings from wp-config.php

By: a guest on Oct 3rd, 2010  |  syntax: Bash  |  size: 0.80 KB  |  hits: 239  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. CONFIG=`find . -name wp-config.php -maxdepth 2 | head -n 1`
  4.  
  5. if [ ! -f $CONFIG ]; then
  6.         echo "Could not find wp-config in this folder or one folder deep."
  7.         exit 3
  8. fi
  9.  
  10. DB_NAME=`echo "<?php include '${CONFIG}'; echo DB_NAME;" | php`
  11. DB_USER=`echo "<?php include '${CONFIG}'; echo DB_USER;" | php`
  12. DB_PASS=`echo "<?php include '${CONFIG}'; echo DB_PASSWORD;" | php`
  13. DB_HOST=`echo "<?php include '${CONFIG}'; echo DB_HOST;" | php`
  14.  
  15. DUMP_PATH=db.sql
  16. ## Alternate name with database name and date:
  17. #DUMP_PATH=${DB_NAME}-$(date +%Y%m%d).sql
  18.  
  19. echo -n "Dumping database to ${DUMP_PATH}... "
  20.  
  21. mysqldump --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} \
  22.  --databases ${DB_NAME} \
  23.  > ${DUMP_PATH}
  24.  
  25. if [ "$?" -ne "0" ]; then
  26.         echo "DB dump failed."
  27.         exit 1
  28. fi
  29. echo "Done"
  30.  
  31. exit $?