This repo will contains useful scripts
- Clone this repository :
git clone [email protected]:strlud/scripts.git - Add the script executable :
chmod +x importDb.sh exportDb.sh - If you want to use these scripts everywhere on your machine, you can create a symlink (or cp the script) in your
/usr/local/binfor example :sudo cp "$PWD/exportDb.sh" /usr/local/bin/exportDbsudo cp "$PWD/importDb.sh" /usr/local/bin/importDb
- You can now do
exportDb -horimportDb -hto see help message everywhere
This script allow you to export a mysql or pgsql database. You could export a db from a docker or your local machine. Compressed or not. The dump's name will be : db_name-year_month_day-hour_minute_second.[pgsql|sql|sql.gz]
Example : You must specify the type of database you want to export
- Export a MySQL database from your local machine NOT compressed :
exportDb --db-type=mysql --user=root --db=my_db --path=/tmp/dump - Export a MySQL database from your local machine compressed:
exportDb --db-type=mysql --user=root --db=my_db --path=/tmp/dump -zipped - Export a PostgresSQL database from your local machine :
exportDb --db-type=pgsql --user=root --db=my_db --path=/tmp/dump - Export a MySQL database from a docker NOT compressed :
exportDb --db-type=mysql --user=root --db=my_db --path=/tmp/dump --docker-name=db_docker - Export a MySQL database from a docker compressed :
exportDb --db-type=mysql --user=root --db=my_db --path=/tmp/dump --docker-name=db_docker -zipped - Export a PostgresSQL database from a docker :
exportDb --db-type=pgsql --user=root --db=my_db --path=/tmp/dump --docker-name=db_docker
Good to know:
--db-typethe type of db you want to export :pgsqlormysql--useris an alias of--db-useris the name of your user db--dbis an alias of--db-nameis the name of your database--pathis an alias of--out-pathis the path on your local machin where you want the dump--dockeris an alias of--docker-nameis the name of your docker which contains the mysql server (optional)-zippedis an option to tell to export the db compressed (optional) ONLY formysqldatabase
This script allow you to import a mysql or pgsql database It should be used after the export.
Example of how to use it :
- Import database with a mysql local :
importDb --user=root --db=my_db --path=/tmp/dump/my_db.sql - Import database into a docker :
importDb --user=root --db=my_db --path=/tmp/dump/my_db.sql --docker=gt_bdd
Good to know:
--useris an alias of--db-useris the name of your user db--dbis an alias of--db-nameis the name of your database--pathis an alias of--from-pathis the path on your local machine where the dump is. The extension must be.sqlor.sql.gzor.pgsql--dockeris an alias of--docker-nameis the name of your docker which contains the mysql server (optional)