From 62450d20cc06a9d63a586bf40ec0cc8a1109e675 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 28 Sep 2010 02:35:32 +0200 Subject: [PATCH] Add simple script to allow for exporting database structure. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- bin/export_sql.bash | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100755 bin/export_sql.bash diff --git a/bin/export_sql.bash b/bin/export_sql.bash new file mode 100755 index 0000000..ceefc73 --- /dev/null +++ b/bin/export_sql.bash @@ -0,0 +1,156 @@ +#!/bin/bash + +# This script is used to export the MySQL structure of the plat/al MySQL +# databases. + + +# Developers: list 'public' tables here. +SHARED_TABLES="account_types +forums +geoloc_administrative_areas +geoloc_countries +geoloc_localities +geoloc_subadministrativeareas +log_actions +newsletter_cat +profile_binet_enum +profile_corps_enum +profile_corps_rank_enum +profile_education_degree_enum +profile_education_enum +profile_education_field_enum +profile_job_alternate +profile_job_entreprise_term +profile_job_enum +profile_job_sector_enum +profile_job_subsector_enum +profile_job_subsubsector_enum +profile_job_term_enum +profile_job_term_relation +profile_langskills_enum +profile_medal_enum +profile_medal_grade_enum +profile_name_enum +profile_networking_enum +profile_section_enum +profile_skill_enum +reminder_type +skin" + +usage() +{ +cat << EOF +usage: $0 OPTIONS + +Will dump the necessary data from MySQL. +Note that all options should have sane defaults if you have correctly configured +your .my.cnf file. + +OPTIONS: +-h Show this message +-H HOST MySQL host to connect to (default: none) +-P PORT MySQL port to connect to (default: none) +-u USER User for MySQL (default: none) +-p PASS MySQL password to use (default: none) +-d SQL_DB Database to read from (default: x5dat) +-n Dry run, don't actually write anything +-o FILE Write to file instead of stdout (- for stdout as well) + +EOF +} + +HOST= +PASS= +PORT= +USER= +SQL_DB="x5dat" +FILE="-" +DRY_RUN=0 + +while getopts "hns:u:p:o:" OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + n) + DRY_RUN=1 + ;; + o) + FILE=$OPTARG + ;; + p) + PASS=$OPTARG + ;; + H) + HOST=$OPTARG + ;; + P) + PORT=$OPTARG + ;; + u) + USER=$OPTARG + ;; + d) + SQL_DB=$OPTARG + ;; + ?) + usage + exit + ;; + esac +done + + +DUMPER="mysqldump --add-drop-table --default-character-set=utf8 --force" + +if [ -n "$USER" ]; then + DUMPER="$DUMPER --user=$USER" +fi + +if [ -n "$PASS" ]; then + DUMPER="$DUMPER --password=$PASS" +fi + +if [ -n "$HOST" ]; then + DUMPER="$DUMPER --host=$HOST" +fi + +if [ -n "$PORT" ]; then + DUMPER="$DUMPER --port=$PORT" +fi + +if [ "$FILE" == "-" ]; then + FILE="" +else + if [ $DRY_RUN -ne 1 ]; then + # Blank the file + echo "" > $FILE + fi +fi + +dump () { + local command=$1 + + if [ $DRY_RUN -eq 1 ]; then + if [ -n "$FILE" ]; then + echo "$command >> $FILE" + else + echo $command + fi + else + if [ -n "$FILE" ]; then + $command >> $FILE + else + $command + fi + fi +} + +# Dump structure +STRUCT_DUMPER="$DUMPER --no-data $SQL_DB" +dump "$STRUCT_DUMPER" + +SHARED_DUMPER="$DUMPER $SQL_DB $SHARED_TABLES" +dump "$SHARED_DUMPER" -- 2.1.4