Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. TEMP=`getopt -o h:: --long host-pass:,host-user:,host-db:,db: -n 'db.sh' -- "$@"`
  4. DEFAULT_HOST="localhost"
  5. DEFAULT_USER="root"
  6. DEFAULT_PASSWORD=""
  7. DEFAULT_FILE="db.sql"
  8.  
  9. eval set -- "$TEMP"
  10.  
  11. while true ; do
  12. case "$1" in
  13. --help)
  14. echo "" ; shift 2 ;;
  15. -h)
  16. case "$2" in
  17. "") HOST=$DEFAULT_HOST ; shift 2 ;;
  18. *) HOST=$2 ; shift 2 ;;
  19. esac ;;
  20. --host-user)
  21. HOST_USER=$2 ; shift 2 ;;
  22. --host-pass)
  23. HOST_PASS=$2 ; shift 2 ;;
  24. --db)
  25. DB=$2 ; shift 2 ;;
  26. --host-db)
  27. HOST_DB=$2 ; shift 2 ;;
  28. --) shift ; break ;;
  29. esac
  30. done
  31.  
  32. echo "downloading $HOST_DB and writing to $DEFAULT_FILE"
  33. mysqldump -u$HOST_USER -p$HOST_PASS -h$HOST $HOST_DB > $DEFAULT_FILE
  34. echo "importing $DEFAULT_FILE to $DB"
  35. mysql -u$DEFAULT_USER -p$DEFAULT_PASSWORD $DB < $DEFAULT_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement