Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active April 24, 2018 16:04
Show Gist options
  • Save dgoguerra/1da39309a55b6147efc3dd260745c19b to your computer and use it in GitHub Desktop.
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
#!/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