Skip to content

Instantly share code, notes, and snippets.

@Veve2
Created March 1, 2016 13:54
Show Gist options
  • Save Veve2/9a60305e0724c05e6de3 to your computer and use it in GitHub Desktop.
Save Veve2/9a60305e0724c05e6de3 to your computer and use it in GitHub Desktop.
Script to dump a mysql database from the parameters of a Symfony project (script from A.L, http://stackoverflow.com/a/35724475/4074148)
#!/bin/bash
# See http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in/23905052#23905052
ROOT=$(readlink -f $(dirname "$0"))
cd $ROOT
# Get database parameters
dbname=$(grep "database_name" ./app/config/parameters.yml | cut -d " " -f 6)
dbuser=$(grep "database_user" ./app/config/parameters.yml | cut -d " " -f 6)
dbpassword=$(grep "database_password" ./app/config/parameters.yml | cut -d " " -f 6)
filename="$(date '+%Y-%m-%d_%H-%M-%S').sql"
echo "Export $dbname database"
mysqldump -B "$dbname" -u "$dbuser" --password="$dbpassword" > "$filename"
echo "Output file :"
ls -lh "$filename"
@Veve2
Copy link
Author

Veve2 commented Mar 1, 2016

Save this in the root of your Symfony project (e.g. mysqldump.sh)

$ bash mysqldump.sh
Export […] database
Warning: Using a password on the command line interface can be insecure.
Output file :
-rw-rw-r-- 1 […] […] 1,8M march 1 14:39 2016-03-01_14-39-08.sql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment