Update table list.
[platal.git] / bin / export_sql.bash
CommitLineData
62450d20
RB
1#!/bin/bash
2
3# This script is used to export the MySQL structure of the plat/al MySQL
4# databases.
5
6
7# Developers: list 'public' tables here.
8SHARED_TABLES="account_types
9forums
fdf0eca0 10geoloc_administrativeareas
62450d20
RB
11geoloc_countries
12geoloc_localities
13geoloc_subadministrativeareas
14log_actions
15newsletter_cat
16profile_binet_enum
17profile_corps_enum
18profile_corps_rank_enum
19profile_education_degree_enum
20profile_education_enum
21profile_education_field_enum
62450d20
RB
22profile_job_entreprise_term
23profile_job_enum
62450d20
RB
24profile_job_term_enum
25profile_job_term_relation
fdf0eca0 26profile_langskill_enum
62450d20
RB
27profile_medal_enum
28profile_medal_grade_enum
29profile_name_enum
30profile_networking_enum
31profile_section_enum
32profile_skill_enum
33reminder_type
fdf0eca0 34skins"
62450d20
RB
35
36usage()
37{
38cat << EOF
39usage: $0 OPTIONS
40
41Will dump the necessary data from MySQL.
42Note that all options should have sane defaults if you have correctly configured
43your .my.cnf file.
44
45OPTIONS:
46-h Show this message
47-H HOST MySQL host to connect to (default: none)
48-P PORT MySQL port to connect to (default: none)
49-u USER User for MySQL (default: none)
50-p PASS MySQL password to use (default: none)
51-d SQL_DB Database to read from (default: x5dat)
52-n Dry run, don't actually write anything
53-o FILE Write to file instead of stdout (- for stdout as well)
54
55EOF
56}
57
58HOST=
59PASS=
60PORT=
61USER=
62SQL_DB="x5dat"
63FILE="-"
64DRY_RUN=0
65
66while getopts "hns:u:p:o:" OPTION
67do
68 case $OPTION in
69 h)
70 usage
71 exit 1
72 ;;
73 n)
74 DRY_RUN=1
75 ;;
76 o)
77 FILE=$OPTARG
78 ;;
79 p)
80 PASS=$OPTARG
81 ;;
82 H)
83 HOST=$OPTARG
84 ;;
85 P)
86 PORT=$OPTARG
87 ;;
88 u)
89 USER=$OPTARG
90 ;;
91 d)
92 SQL_DB=$OPTARG
93 ;;
94 ?)
95 usage
96 exit
97 ;;
98 esac
99done
100
101
102DUMPER="mysqldump --add-drop-table --default-character-set=utf8 --force"
103
104if [ -n "$USER" ]; then
105 DUMPER="$DUMPER --user=$USER"
106fi
107
108if [ -n "$PASS" ]; then
109 DUMPER="$DUMPER --password=$PASS"
110fi
111
112if [ -n "$HOST" ]; then
113 DUMPER="$DUMPER --host=$HOST"
114fi
115
116if [ -n "$PORT" ]; then
117 DUMPER="$DUMPER --port=$PORT"
118fi
119
120if [ "$FILE" == "-" ]; then
121 FILE=""
122else
123 if [ $DRY_RUN -ne 1 ]; then
124 # Blank the file
125 echo "" > $FILE
126 fi
127fi
128
129dump () {
130 local command=$1
131
132 if [ $DRY_RUN -eq 1 ]; then
133 if [ -n "$FILE" ]; then
134 echo "$command >> $FILE"
135 else
136 echo $command
137 fi
138 else
139 if [ -n "$FILE" ]; then
140 $command >> $FILE
141 else
142 $command
143 fi
144 fi
145}
146
147# Dump structure
148STRUCT_DUMPER="$DUMPER --no-data $SQL_DB"
149dump "$STRUCT_DUMPER"
150
151SHARED_DUMPER="$DUMPER $SQL_DB $SHARED_TABLES"
152dump "$SHARED_DUMPER"