Last active
April 24, 2018 16:04
-
-
Save dgoguerra/1da39309a55b6147efc3dd260745c19b to your computer and use it in GitHub Desktop.
Dump a Laravel Forge site's DB through SSH using the .env's credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| SERVER="$1" | |
| SITE="$2" | |
| # script to run in the remote host | |
| REMOTE_CMD=" | |
| # ensure the site exists in the user's home | |
| if [ ! -d $SITE ]; then | |
| echo '$SITE' not found, aborting | |
| exit | |
| fi | |
| # ensure .env exists in the site's root | |
| if [ ! -f \"$SITE/.env\" ]; then | |
| echo '.env' not found, aborting | |
| exit | |
| fi | |
| cd $SITE | |
| # load DB related .env vars | |
| export \$(grep '^DB_' .env) | |
| # dump default project's DB | |
| mysqldump -h\$DB_HOST -u\$DB_USERNAME -p\$DB_PASSWORD \$DB_DATABASE | |
| " | |
| ssh "$SERVER" "$REMOTE_CMD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment