Created
June 25, 2020 17:41
-
-
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.
This file contains 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
#!/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