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