Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- source .env
- if [ -z "$1" ]
- then
- echo "Missing file to dump"
- exit 1
- fi
- readonly URI_REGEX='^(([^:\/?#]+):)?(\/\/((([^:\/?#]+):)?(([^:\/?#]+)@)?([^:\/?#]+)(:([0-9]+))?))?(\/([^?#]*))(\?([^#]*))?(#(.*))?'
- # ↑↑ ↑ ↑↑↑ ↑↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
- # |2 scheme | ||6 userinfo |8 passinfo 9 host | 11 port | 13 rpath | 15 query | 17 fragment
- # 1 scheme: | |5 userinfo: 7 passinfo@ 10 :… 12 /path 14 ?… 16 #…
- # | 4
- # 3 //…
- parse_scheme () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[2]}"
- }
- parse_user () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[6]}"
- }
- parse_password () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[8]}"
- }
- parse_host () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[9]}"
- }
- parse_port () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[11]}"
- }
- parse_rpath () {
- [[ "$@" =~ $URI_REGEX ]] && echo "${BASH_REMATCH[13]}"
- }
- #DATABASE_URL="mysql://user:heslo@db:3306/database"
- #parse_scheme $DATABASE_URL
- DB_USER=$(parse_user $DATABASE_URL)
- DB_PASS=$(parse_password $DATABASE_URL)
- DB_HOST=$(parse_host $DATABASE_URL)
- DB_PORT=$(parse_port $DATABASE_URL)
- DB_NAME=$(parse_rpath $DATABASE_URL)
- export MYSQL_PWD=$DB_PASS
- mysqldump -u $DB_USER -h $DB_HOST -P $DB_PORT --databases $DB_NAME > $1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement