Guest User

Untitled

a guest
Oct 11th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. USER=""
  4. PASSWORD=""
  5.  
  6. if [ -z $1 ]; then
  7. echo -e "ERROR: No database name. Usage: export_db DATABASE_NAME"
  8. exit;
  9. fi
  10. DB=$1
  11. OUTPUT_FILE="$DB.sql"
  12.  
  13. if [ -f $OUTPUT_FILE ]; then
  14. read -p "Do you want to replace the existing file $OUTPUT_FILE? [y/n]" yn
  15. case $yn in
  16. [Yy]* )
  17. rm $OUTPUT_FILE;;
  18. * )
  19. timestamp=$(date +%m%d%y%H%M%S);
  20. OUTPUT_FILE=$DB.$timestamp.sql;;
  21. esac
  22. fi
  23.  
  24. mysqldump --user=$ROOT --password=$PASSWORD $DB > $OUTPUT_FILE
  25. if [ $? -ne 0 ]; then
  26. echo "ERROR: Database $DB does not exist";
  27. exit;
  28. fi
  29.  
  30. read -p "Do you need to replace the domain on the db file? [y/n]" yn
  31. case $yn in
  32. [Yy]* )
  33. read -p "Domain name to replace: " $FROM_DOMAIN
  34. read -p "Replace domain name with: " $TO_DOMAIN
  35. perl -pi -w -e "s#${FROM_DOMAIN}#${TO_DOMAIN}#g;" $OUTPUT_FILE;;
  36. * ) ;;
  37. esac
  38.  
  39. read -p "Gzip the file? [y/n]" yn
  40. case $yn in
  41. [Yy]* ) gzip $OUTPUT_FILE;;
  42. * ) ;;
  43. esac
  44.  
  45. echo "**** DB $1 EXPORTED ****"
Add Comment
Please, Sign In to add comment