Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- TEMP=`getopt -o h:: --long host-pass:,host-user:,host-db:,db: -n 'db.sh' -- "$@"`
- DEFAULT_HOST="localhost"
- DEFAULT_USER="root"
- DEFAULT_PASSWORD=""
- DEFAULT_FILE="db.sql"
- eval set -- "$TEMP"
- while true ; do
- case "$1" in
- --help)
- echo "" ; shift 2 ;;
- -h)
- case "$2" in
- "") HOST=$DEFAULT_HOST ; shift 2 ;;
- *) HOST=$2 ; shift 2 ;;
- esac ;;
- --host-user)
- HOST_USER=$2 ; shift 2 ;;
- --host-pass)
- HOST_PASS=$2 ; shift 2 ;;
- --db)
- DB=$2 ; shift 2 ;;
- --host-db)
- HOST_DB=$2 ; shift 2 ;;
- --) shift ; break ;;
- esac
- done
- echo "downloading $HOST_DB and writing to $DEFAULT_FILE"
- mysqldump -u$HOST_USER -p$HOST_PASS -h$HOST $HOST_DB > $DEFAULT_FILE
- echo "importing $DEFAULT_FILE to $DB"
- mysql -u$DEFAULT_USER -p$DEFAULT_PASSWORD $DB < $DEFAULT_FILE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement