Skip to content

Instantly share code, notes, and snippets.

@Clindbergh
Created June 25, 2020 17:41
Show Gist options
  • Save Clindbergh/87232f1dbfe157bd1f0bb2e9bf353cc8 to your computer and use it in GitHub Desktop.
Save Clindbergh/87232f1dbfe157bd1f0bb2e9bf353cc8 to your computer and use it in GitHub Desktop.
Exports a database from a symfony production environment and imports it in a test environment using the database strings declared in the .env files.
#!/bin/bash
prodDbString=$(grep "DATABASE_URL" //httpdocs/prodEnv/releases/current/.env.local)
testDbString=$(grep "DATABASE_URL" //httpdocs/testEnv/releases/current/.env)
function readDbCredentials {
user=$(grep -oP "(?<=mysql\:\/\/)\w+(?=\:)" <<< $1)
pw=$(grep -oP "(?<=mysql\:\/\/$user\:).*(?=\@)" <<< $1)
db=$(grep -oP "\w+$" <<< $1)
}
readDbCredentials $prodDbString
mysqldump --port 3306 -h 127.0.0.1 -u "$user" -p"$pw" "$db" > prodDb.sql
readDbCredentials $testDbString
mysql --port 3306 -h 127.0.0.1 -u "$user" -p"$pw" "$db" < prodDb.sql
rm prodDb.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment