1089.7.1
by Stewart Smith
fix drizzledump copyright header. |
1 |
/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
|
1719.2.3
by Vijay Samuel
Merge removed the drizzled/option.h include from client_priv.h and archive_reader. |
2 |
* Copyright (C) 2010 Vijay Samuel
|
1751.4.10
by Andrew Hutchings
Start of data dump support |
3 |
* Copyright (C) 2010 Andrew Hutchings
|
1
by brian
clean slate |
4 |
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
5 |
This program is free software; you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
|
7 |
the Free Software Foundation; version 2 of the License.
|
|
8 |
||
9 |
This program is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU General Public License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU General Public License
|
|
15 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
16 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
17 |
|
279.2.4
by Monty Taylor
Moved import, check and dump to C++... fixed errors. |
18 |
/* drizzledump.cc - Dump a tables contents and format to an ASCII file
|
1089.7.1
by Stewart Smith
fix drizzledump copyright header. |
19 |
|
20 |
* Derived from mysqldump, which originally came from:
|
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
21 |
**
|
22 |
** The author's original notes follow :-
|
|
23 |
**
|
|
24 |
** AUTHOR: Igor Romanenko (igor@frog.kiev.ua)
|
|
25 |
** DATE: December 3, 1994
|
|
26 |
** WARRANTY: None, expressed, impressed, implied
|
|
27 |
** or other
|
|
28 |
** STATUS: Public domain
|
|
1089.7.3
by Stewart Smith
move drizzledump 'by igor, monty, jani and sinisa' to commment rather than --help as having this in --help may be confusing to users in who to blame for bugs. |
29 |
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
30 |
* and more work by Monty, Jani & Sinisa
|
31 |
* and all the MySQL developers over the years.
|
|
1
by brian
clean slate |
32 |
*/
|
33 |
||
612.2.4
by Monty Taylor
Moved some defines to config.h. Stopped including config.h directly anywhere. |
34 |
#include "client_priv.h" |
279.2.6
by Monty Taylor
Replaced DYN string in drizzledump. |
35 |
#include <string> |
1633.5.1
by Vijay Samuel
Merge trunk |
36 |
#include <iostream> |
1
by brian
clean slate |
37 |
#include <stdarg.h> |
1678.1.1
by Monty Taylor
Removed our unordered wrappers. We use Boost now. |
38 |
#include <boost/unordered_set.hpp> |
758.1.2
by Monty Taylor
Fixed missing include. |
39 |
#include <algorithm> |
1633.5.1
by Vijay Samuel
Merge trunk |
40 |
#include <fstream> |
673.5.11
by Andrew Hutchings
Apply -p means port changes to drizzledump |
41 |
#include <drizzled/gettext.h> |
1633.5.1
by Vijay Samuel
Merge trunk |
42 |
#include <drizzled/configmake.h> |
212.5.42
by Monty Taylor
Ding dong include is dead. |
43 |
#include <drizzled/error.h> |
1633.5.1
by Vijay Samuel
Merge trunk |
44 |
#include <boost/program_options.hpp> |
1751.4.2
by Andrew Hutchings
Switch to using boost::regex instead of pcre |
45 |
#include <boost/regex.hpp> |
1751.4.8
by Andrew Hutchings
Add DOUBLE/DECIMAL and DATE/TIME types with conversions |
46 |
#include <boost/date_time/posix_time/posix_time.hpp> |
2449.1.2
by Brian Aker
Additional fixes for libdrizzle. |
47 |
|
48 |
#include "client/drizzledump_data.h" |
|
49 |
#include "client/drizzledump_mysql.h" |
|
50 |
#include "client/drizzledump_drizzle.h" |
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
51 |
|
2281.7.1
by Andrew Hutchings
Add better shell user detect functionality and add it to console |
52 |
#include "user_detect.h" |
53 |
||
279.2.6
by Monty Taylor
Replaced DYN string in drizzledump. |
54 |
using namespace std; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
55 |
using namespace drizzled; |
1633.5.1
by Vijay Samuel
Merge trunk |
56 |
namespace po= boost::program_options; |
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
57 |
|
1
by brian
clean slate |
58 |
/* Exit codes */
|
59 |
||
60 |
#define EX_USAGE 1
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
61 |
#define EX_DRIZZLEERR 2
|
1
by brian
clean slate |
62 |
#define EX_EOF 5 /* ferror for output file was got */ |
63 |
||
1751.4.23
by Andrew Hutchings
Fix various bugs |
64 |
bool verbose= false; |
1745.2.1
by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar. |
65 |
static bool use_drizzle_protocol= false; |
1799.7.4
by Andrew Hutchings
Fix up some more options and the docs |
66 |
bool ignore_errors= false; |
1059.2.3
by kaleen
code style clean |
67 |
static bool flush_logs= false; |
68 |
static bool create_options= true; |
|
69 |
static bool opt_quoted= false; |
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
70 |
bool opt_databases= false; |
71 |
bool opt_alldbs= false; |
|
1059.2.3
by kaleen
code style clean |
72 |
static bool opt_lock_all_tables= false; |
73 |
static bool opt_dump_date= true; |
|
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
74 |
bool opt_autocommit= false; |
1059.2.3
by kaleen
code style clean |
75 |
static bool opt_single_transaction= false; |
1799.7.6
by Andrew Hutchings
Fix comments appearing in test cases |
76 |
static bool opt_comments; |
1633.5.1
by Vijay Samuel
Merge trunk |
77 |
static bool opt_compact; |
1751.4.26
by Andrew Hutchings
Fix up for the drizzledump test cases |
78 |
bool opt_ignore= false; |
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
79 |
bool opt_drop_database; |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
80 |
bool opt_no_create_info; |
81 |
bool opt_no_data= false; |
|
82 |
bool opt_create_db= false; |
|
83 |
bool opt_disable_keys= true; |
|
84 |
bool extended_insert= true; |
|
85 |
bool opt_replace_into= false; |
|
86 |
bool opt_drop= true; |
|
2121.8.1
by Andrew Hutchings
Add option --my-data-is-mangled to drizzledump to prevent further corruption by retrieving UTF8 data stored in a non-UTF8 table during a MySQL -> Drizzle conversion |
87 |
bool opt_data_is_mangled= false; |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
88 |
uint32_t show_progress_size= 0; |
279.2.6
by Monty Taylor
Replaced DYN string in drizzledump. |
89 |
static string insert_pat; |
673.5.11
by Andrew Hutchings
Apply -p means port changes to drizzledump |
90 |
static uint32_t opt_drizzle_port= 0; |
91 |
static int first_error= 0; |
|
279.2.6
by Monty Taylor
Replaced DYN string in drizzledump. |
92 |
static string extended_row; |
1
by brian
clean slate |
93 |
FILE *md_result_file= 0; |
673.5.11
by Andrew Hutchings
Apply -p means port changes to drizzledump |
94 |
FILE *stderror_file= 0; |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
95 |
std::vector<DrizzleDumpDatabase*> database_store; |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
96 |
DrizzleDumpConnection* db_connection; |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
97 |
DrizzleDumpConnection* destination_connection; |
98 |
||
99 |
enum destinations { |
|
100 |
DESTINATION_DB, |
|
101 |
DESTINATION_FILES, |
|
102 |
DESTINATION_STDOUT
|
|
103 |
};
|
|
104 |
||
105 |
int opt_destination= DESTINATION_STDOUT; |
|
106 |
std::string opt_destination_host; |
|
107 |
uint16_t opt_destination_port; |
|
108 |
std::string opt_destination_user; |
|
109 |
std::string opt_destination_password; |
|
110 |
std::string opt_destination_database; |
|
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
111 |
|
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
112 |
const string progname= "drizzledump"; |
113 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
114 |
string password, |
115 |
enclosed, |
|
116 |
escaped, |
|
117 |
current_host, |
|
118 |
path, |
|
119 |
current_user, |
|
120 |
opt_password, |
|
1745.2.1
by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar. |
121 |
opt_protocol, |
1633.5.1
by Vijay Samuel
Merge trunk |
122 |
where; |
123 |
||
1678.1.1
by Monty Taylor
Removed our unordered wrappers. We use Boost now. |
124 |
boost::unordered_set<string> ignore_table; |
1
by brian
clean slate |
125 |
|
1751.4.25
by Andrew Hutchings
Fix error handling |
126 |
void maybe_exit(int error); |
1
by brian
clean slate |
127 |
static void die(int error, const char* reason, ...); |
1751.4.23
by Andrew Hutchings
Fix various bugs |
128 |
static void write_header(char *db_name); |
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
129 |
static int dump_selected_tables(const string &db, const vector<string> &table_names); |
130 |
static int dump_databases(const vector<string> &db_names); |
|
53.2.4
by Monty Taylor
Changes so that client/ builds cleanly with no warnings. |
131 |
static int dump_all_databases(void); |
1751.4.1
by Andrew Hutchings
Add functionality to detect server type we are connecting to |
132 |
int get_server_type(); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
133 |
void dump_all_tables(void); |
134 |
void generate_dump(void); |
|
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
135 |
void generate_dump_db(void); |
1751.4.1
by Andrew Hutchings
Add functionality to detect server type we are connecting to |
136 |
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
137 |
void dump_all_tables(void) |
138 |
{
|
|
139 |
std::vector<DrizzleDumpDatabase*>::iterator i; |
|
140 |
for (i= database_store.begin(); i != database_store.end(); ++i) |
|
141 |
{
|
|
1799.7.4
by Andrew Hutchings
Fix up some more options and the docs |
142 |
if ((not (*i)->populateTables()) && (not ignore_errors)) |
1751.4.25
by Andrew Hutchings
Fix error handling |
143 |
maybe_exit(EX_DRIZZLEERR); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
144 |
}
|
145 |
}
|
|
146 |
||
147 |
void generate_dump(void) |
|
148 |
{
|
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
149 |
std::vector<DrizzleDumpDatabase*>::iterator i; |
1751.4.23
by Andrew Hutchings
Fix various bugs |
150 |
|
151 |
if (path.empty()) |
|
152 |
{
|
|
153 |
cout << endl << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;" |
|
154 |
<< endl << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl; |
|
155 |
}
|
|
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
156 |
|
157 |
if (opt_autocommit) |
|
158 |
cout << "SET AUTOCOMMIT=0;" << endl; |
|
159 |
||
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
160 |
for (i= database_store.begin(); i != database_store.end(); ++i) |
161 |
{
|
|
162 |
DrizzleDumpDatabase *database= *i; |
|
163 |
cout << *database; |
|
164 |
}
|
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
165 |
|
166 |
if (path.empty()) |
|
167 |
{
|
|
168 |
cout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" |
|
169 |
<< endl << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl; |
|
170 |
}
|
|
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
171 |
}
|
172 |
||
173 |
void generate_dump_db(void) |
|
174 |
{
|
|
175 |
std::vector<DrizzleDumpDatabase*>::iterator i; |
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
176 |
DrizzleStringBuf sbuf(1024); |
1802.6.1
by Andrew Hutchings
Add better error handling and exception handling for database connect |
177 |
try
|
178 |
{
|
|
179 |
destination_connection= new DrizzleDumpConnection(opt_destination_host, |
|
180 |
opt_destination_port, opt_destination_user, opt_destination_password, |
|
181 |
false); |
|
182 |
}
|
|
1966.3.1
by Monty Taylor
Use std::exception instead of catch(...) |
183 |
catch (std::exception&) |
1802.6.1
by Andrew Hutchings
Add better error handling and exception handling for database connect |
184 |
{
|
185 |
cerr << "Could not connect to destination database server" << endl; |
|
186 |
maybe_exit(EX_DRIZZLEERR); |
|
187 |
}
|
|
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
188 |
sbuf.setConnection(destination_connection); |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
189 |
std::ostream sout(&sbuf); |
1855.1.1
by Andrew Hutchings
Fix several bugs dumping tables with many rows |
190 |
sout.exceptions(ios_base::badbit); |
1751.4.23
by Andrew Hutchings
Fix various bugs |
191 |
|
192 |
if (path.empty()) |
|
193 |
{
|
|
194 |
sout << "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;" << endl; |
|
195 |
sout << "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;" << endl; |
|
196 |
}
|
|
197 |
||
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
198 |
if (opt_autocommit) |
199 |
cout << "SET AUTOCOMMIT=0;" << endl; |
|
200 |
||
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
201 |
for (i= database_store.begin(); i != database_store.end(); ++i) |
202 |
{
|
|
1855.1.1
by Andrew Hutchings
Fix several bugs dumping tables with many rows |
203 |
try
|
204 |
{
|
|
205 |
DrizzleDumpDatabase *database= *i; |
|
206 |
sout << *database; |
|
207 |
}
|
|
1966.3.1
by Monty Taylor
Use std::exception instead of catch(...) |
208 |
catch (std::exception&) |
1855.1.1
by Andrew Hutchings
Fix several bugs dumping tables with many rows |
209 |
{
|
1880.2.1
by Andrew Hutchings
Add quoting to the end of the table definition |
210 |
std::cout << _("Error inserting into destination database") << std::endl; |
1855.1.1
by Andrew Hutchings
Fix several bugs dumping tables with many rows |
211 |
if (not ignore_errors) |
212 |
maybe_exit(EX_DRIZZLEERR); |
|
213 |
}
|
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
214 |
}
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
215 |
|
216 |
if (path.empty()) |
|
217 |
{
|
|
218 |
sout << "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;" << endl; |
|
219 |
sout << "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;" << endl; |
|
220 |
}
|
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
221 |
}
|
222 |
||
1
by brian
clean slate |
223 |
/*
|
224 |
exit with message if ferror(file)
|
|
225 |
||
226 |
SYNOPSIS
|
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
227 |
check_io()
|
228 |
file - checked file
|
|
1
by brian
clean slate |
229 |
*/
|
230 |
||
53.2.4
by Monty Taylor
Changes so that client/ builds cleanly with no warnings. |
231 |
static void check_io(FILE *file) |
1
by brian
clean slate |
232 |
{
|
233 |
if (ferror(file)) |
|
758.2.3
by Andrew Hutchings
Remove compatibility comments from drizzledump |
234 |
die(EX_EOF, _("Got errno %d on write"), errno); |
1
by brian
clean slate |
235 |
}
|
236 |
||
1751.4.23
by Andrew Hutchings
Fix various bugs |
237 |
static void write_header(char *db_name) |
1
by brian
clean slate |
238 |
{
|
1799.7.6
by Andrew Hutchings
Fix comments appearing in test cases |
239 |
if ((not opt_compact) and (opt_comments)) |
1751.4.23
by Andrew Hutchings
Fix various bugs |
240 |
{
|
241 |
cout << "-- drizzledump " << VERSION << " libdrizzle " |
|
242 |
<< drizzle_version() << ", for " << HOST_VENDOR << "-" << HOST_OS |
|
243 |
<< " (" << HOST_CPU << ")" << endl << "--" << endl; |
|
244 |
cout << "-- Host: " << current_host << " Database: " << db_name << endl; |
|
245 |
cout << "-- ------------------------------------------------------" << endl; |
|
246 |
cout << "-- Server version\t" << db_connection->getServerVersion(); |
|
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
247 |
if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) |
1751.4.23
by Andrew Hutchings
Fix various bugs |
248 |
cout << " (MySQL server)"; |
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
249 |
else if (db_connection->getServerType() == ServerDetect::SERVER_DRIZZLE_FOUND) |
1751.4.23
by Andrew Hutchings
Fix various bugs |
250 |
cout << " (Drizzle server)"; |
251 |
cout << endl << endl; |
|
1
by brian
clean slate |
252 |
}
|
2219.3.1
by Andrew Hutchings
If drizzledump is run with --single-transaction it will now try and probe the sys_replication_log table. If successful it will output something like: |
253 |
|
1
by brian
clean slate |
254 |
} /* write_header */ |
255 |
||
256 |
||
257 |
static void write_footer(FILE *sql_file) |
|
258 |
{
|
|
1751.4.7
by Andrew Hutchings
Add index support |
259 |
if (! opt_compact) |
1
by brian
clean slate |
260 |
{
|
1799.7.6
by Andrew Hutchings
Fix comments appearing in test cases |
261 |
if (opt_comments) |
1
by brian
clean slate |
262 |
{
|
1799.7.6
by Andrew Hutchings
Fix comments appearing in test cases |
263 |
if (opt_dump_date) |
264 |
{
|
|
265 |
boost::posix_time::ptime time(boost::posix_time::second_clock::local_time()); |
|
266 |
fprintf(sql_file, "-- Dump completed on %s\n", |
|
267 |
boost::posix_time::to_simple_string(time).c_str()); |
|
268 |
}
|
|
269 |
else
|
|
270 |
fprintf(sql_file, "-- Dump completed\n"); |
|
1
by brian
clean slate |
271 |
}
|
272 |
check_io(sql_file); |
|
273 |
}
|
|
274 |
} /* write_footer */ |
|
275 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
276 |
static int get_options(void) |
277 |
{
|
|
1
by brian
clean slate |
278 |
if (opt_single_transaction && opt_lock_all_tables) |
279 |
{
|
|
758.2.3
by Andrew Hutchings
Remove compatibility comments from drizzledump |
280 |
fprintf(stderr, _("%s: You can't use --single-transaction and " |
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
281 |
"--lock-all-tables at the same time.\n"), progname.c_str()); |
1
by brian
clean slate |
282 |
return(EX_USAGE); |
283 |
}
|
|
1633.5.1
by Vijay Samuel
Merge trunk |
284 |
if ((opt_databases || opt_alldbs) && ! path.empty()) |
1
by brian
clean slate |
285 |
{
|
286 |
fprintf(stderr, |
|
758.2.3
by Andrew Hutchings
Remove compatibility comments from drizzledump |
287 |
_("%s: --databases or --all-databases can't be used with --tab.\n"), |
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
288 |
progname.c_str()); |
1
by brian
clean slate |
289 |
return(EX_USAGE); |
290 |
}
|
|
1633.5.1
by Vijay Samuel
Merge trunk |
291 |
|
1
by brian
clean slate |
292 |
if (tty_password) |
928.1.4
by Eric Day
Fixed a few bugs, more progress on conversion. |
293 |
opt_password=client_get_tty_password(NULL); |
1
by brian
clean slate |
294 |
return(0); |
295 |
} /* get_options */ |
|
296 |
||
297 |
||
298 |
/*
|
|
299 |
Prints out an error message and kills the process.
|
|
300 |
||
301 |
SYNOPSIS
|
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
302 |
die()
|
303 |
error_num - process return value
|
|
304 |
fmt_reason - a format string for use by vsnprintf.
|
|
305 |
... - variable arguments for above fmt_reason string
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
306 |
|
1
by brian
clean slate |
307 |
DESCRIPTION
|
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
308 |
This call prints out the formatted error message to stderr and then
|
309 |
terminates the process.
|
|
1
by brian
clean slate |
310 |
*/
|
311 |
static void die(int error_num, const char* fmt_reason, ...) |
|
312 |
{
|
|
313 |
char buffer[1000]; |
|
314 |
va_list args; |
|
315 |
va_start(args,fmt_reason); |
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
316 |
vsnprintf(buffer, sizeof(buffer), fmt_reason, args); |
1
by brian
clean slate |
317 |
va_end(args); |
318 |
||
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
319 |
fprintf(stderr, "%s: %s\n", progname.c_str(), buffer); |
1
by brian
clean slate |
320 |
fflush(stderr); |
321 |
||
322 |
ignore_errors= 0; /* force the exit */ |
|
323 |
maybe_exit(error_num); |
|
324 |
}
|
|
325 |
||
53.2.4
by Monty Taylor
Changes so that client/ builds cleanly with no warnings. |
326 |
static void free_resources(void) |
1
by brian
clean slate |
327 |
{
|
328 |
if (md_result_file && md_result_file != stdout) |
|
910.1.3
by Brian Aker
Remove my_fopen() and key_map.cc file (thanks to Jay's lcov) |
329 |
fclose(md_result_file); |
1633.5.1
by Vijay Samuel
Merge trunk |
330 |
opt_password.erase(); |
1
by brian
clean slate |
331 |
}
|
332 |
||
333 |
||
1751.4.25
by Andrew Hutchings
Fix error handling |
334 |
void maybe_exit(int error) |
1
by brian
clean slate |
335 |
{
|
336 |
if (!first_error) |
|
337 |
first_error= error; |
|
338 |
if (ignore_errors) |
|
339 |
return; |
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
340 |
delete db_connection; |
1883.3.1
by Andrew Hutchings
Cleanup drizzledump and drizzle for cppcheck |
341 |
delete destination_connection; |
1
by brian
clean slate |
342 |
free_resources(); |
343 |
exit(error); |
|
344 |
}
|
|
345 |
||
346 |
static int dump_all_databases() |
|
347 |
{
|
|
928.1.4
by Eric Day
Fixed a few bugs, more progress on conversion. |
348 |
drizzle_row_t row; |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
349 |
drizzle_result_st *tableres; |
1
by brian
clean slate |
350 |
int result=0; |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
351 |
std::string query; |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
352 |
DrizzleDumpDatabase *database; |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
353 |
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
354 |
if (verbose) |
355 |
std::cerr << _("-- Retrieving database structures...") << std::endl; |
|
356 |
||
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
357 |
/* Blocking the MySQL privilege tables too because we can't import them due to bug#646187 */
|
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
358 |
if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
359 |
query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql')"; |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
360 |
else
|
361 |
query= "SELECT SCHEMA_NAME, DEFAULT_COLLATION_NAME FROM DATA_DICTIONARY.SCHEMAS WHERE SCHEMA_NAME NOT IN ('information_schema','data_dictionary')"; |
|
362 |
||
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
363 |
tableres= db_connection->query(query); |
364 |
while ((row= drizzle_row_next(tableres))) |
|
1
by brian
clean slate |
365 |
{
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
366 |
std::string database_name(row[0]); |
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
367 |
if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
368 |
database= new DrizzleDumpDatabaseMySQL(database_name, db_connection); |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
369 |
else
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
370 |
database= new DrizzleDumpDatabaseDrizzle(database_name, db_connection); |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
371 |
|
1751.4.6
by Andrew Hutchings
More fixups |
372 |
database->setCollate(row[1]); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
373 |
database_store.push_back(database); |
1
by brian
clean slate |
374 |
}
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
375 |
db_connection->freeResult(tableres); |
1
by brian
clean slate |
376 |
return result; |
377 |
}
|
|
378 |
/* dump_all_databases */
|
|
379 |
||
380 |
||
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
381 |
static int dump_databases(const vector<string> &db_names) |
1
by brian
clean slate |
382 |
{
|
383 |
int result=0; |
|
1633.5.1
by Vijay Samuel
Merge trunk |
384 |
string temp; |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
385 |
DrizzleDumpDatabase *database; |
386 |
||
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
387 |
for (vector<string>::const_iterator it= db_names.begin(); it != db_names.end(); ++it) |
1
by brian
clean slate |
388 |
{
|
1633.5.1
by Vijay Samuel
Merge trunk |
389 |
temp= *it; |
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
390 |
if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
391 |
database= new DrizzleDumpDatabaseMySQL(temp, db_connection); |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
392 |
else
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
393 |
database= new DrizzleDumpDatabaseDrizzle(temp, db_connection); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
394 |
database_store.push_back(database); |
1
by brian
clean slate |
395 |
}
|
142.1.2
by Patrick
All DBUG_x removed from client/ |
396 |
return(result); |
1
by brian
clean slate |
397 |
} /* dump_databases */ |
398 |
||
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
399 |
static int dump_selected_tables(const string &db, const vector<string> &table_names) |
1
by brian
clean slate |
400 |
{
|
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
401 |
DrizzleDumpDatabase *database; |
402 |
||
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
403 |
if (db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
404 |
database= new DrizzleDumpDatabaseMySQL(db, db_connection); |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
405 |
else
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
406 |
database= new DrizzleDumpDatabaseDrizzle(db, db_connection); |
1751.4.19
by Andrew Hutchings
Put drizzle and mysql processes in seperate classes/files |
407 |
|
1751.4.25
by Andrew Hutchings
Fix error handling |
408 |
if (not database->populateTables(table_names)) |
409 |
{
|
|
410 |
delete database; |
|
1799.7.4
by Andrew Hutchings
Fix up some more options and the docs |
411 |
if (not ignore_errors) |
412 |
maybe_exit(EX_DRIZZLEERR); |
|
1751.4.25
by Andrew Hutchings
Fix error handling |
413 |
}
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
414 |
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
415 |
database_store.push_back(database); |
1
by brian
clean slate |
416 |
|
1054.1.1
by Brian Aker
Remove guts in parser for LOCK TABLE. |
417 |
return 0; |
1
by brian
clean slate |
418 |
} /* dump_selected_tables */ |
419 |
||
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
420 |
static int do_flush_tables_read_lock() |
1
by brian
clean slate |
421 |
{
|
422 |
/*
|
|
423 |
We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
|
|
424 |
will wait but will not stall the whole mysqld, and when the long update is
|
|
425 |
done the FLUSH TABLES WITH READ LOCK will start and succeed quickly. So,
|
|
1351.1.3
by stefan
some minor mysql->drizzle replacements |
426 |
FLUSH TABLES is to lower the probability of a stage where both drizzled
|
1
by brian
clean slate |
427 |
and most client connections are stalled. Of course, if a second long
|
428 |
update starts between the two FLUSHes, we have that bad stall.
|
|
429 |
*/
|
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
430 |
|
431 |
db_connection->queryNoResult("FLUSH TABLES"); |
|
432 |
db_connection->queryNoResult("FLUSH TABLES WITH READ LOCK"); |
|
433 |
||
434 |
return 0; |
|
435 |
}
|
|
436 |
||
437 |
static int start_transaction() |
|
438 |
{
|
|
439 |
db_connection->queryNoResult("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ"); |
|
440 |
db_connection->queryNoResult("START TRANSACTION WITH CONSISTENT SNAPSHOT"); |
|
2219.3.1
by Andrew Hutchings
If drizzledump is run with --single-transaction it will now try and probe the sys_replication_log table. If successful it will output something like: |
441 |
|
442 |
if (db_connection->getServerType() == ServerDetect::SERVER_DRIZZLE_FOUND) |
|
443 |
{
|
|
444 |
drizzle_result_st *result; |
|
445 |
drizzle_row_t row; |
|
446 |
std::string query("SELECT COMMIT_ID, ID FROM DATA_DICTIONARY.SYS_REPLICATION_LOG WHERE COMMIT_ID=(SELECT MAX(COMMIT_ID) FROM DATA_DICTIONARY.SYS_REPLICATION_LOG)"); |
|
447 |
result= db_connection->query(query); |
|
448 |
if ((row= drizzle_row_next(result))) |
|
449 |
{
|
|
450 |
cout << "-- SYS_REPLICATION_LOG: COMMIT_ID = " << row[0] << ", ID = " << row[1] << endl << endl; |
|
451 |
}
|
|
452 |
db_connection->freeResult(result); |
|
453 |
}
|
|
454 |
||
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
455 |
return 0; |
1751.4.1
by Andrew Hutchings
Add functionality to detect server type we are connecting to |
456 |
}
|
457 |
||
1
by brian
clean slate |
458 |
int main(int argc, char **argv) |
459 |
{
|
|
1633.5.1
by Vijay Samuel
Merge trunk |
460 |
try
|
461 |
{
|
|
1
by brian
clean slate |
462 |
int exit_code; |
463 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
464 |
#if defined(ENABLE_NLS)
|
465 |
# if defined(HAVE_LOCALE_H)
|
|
466 |
setlocale(LC_ALL, ""); |
|
467 |
# endif
|
|
468 |
bindtextdomain("drizzle7", LOCALEDIR); |
|
469 |
textdomain("drizzle7"); |
|
470 |
#endif
|
|
471 |
||
472 |
po::options_description commandline_options(_("Options used only in command line")); |
|
1633.5.1
by Vijay Samuel
Merge trunk |
473 |
commandline_options.add_options() |
474 |
("all-databases,A", po::value<bool>(&opt_alldbs)->default_value(false)->zero_tokens(), |
|
2068.4.1
by Andrew Hutchings
Fix intl domain |
475 |
_("Dump all the databases. This will be same as --databases with all databases selected.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
476 |
("flush-logs,F", po::value<bool>(&flush_logs)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
477 |
_("Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --flush-logs")) |
1633.5.1
by Vijay Samuel
Merge trunk |
478 |
("force,f", po::value<bool>(&ignore_errors)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
479 |
_("Continue even if we get an sql-error.")) |
480 |
("help,?", _("Display this help message and exit.")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
481 |
("lock-all-tables,x", po::value<bool>(&opt_lock_all_tables)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
482 |
_("Locks all tables across all databases. This is achieved by taking a global read lock for the duration of the whole dump. Automatically turns --single-transaction off.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
483 |
("single-transaction", po::value<bool>(&opt_single_transaction)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
484 |
_("Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
485 |
("skip-opt", |
2068.4.1
by Andrew Hutchings
Fix intl domain |
486 |
_("Disable --opt. Disables --add-drop-table, --add-locks, --create-options, ---extended-insert and --disable-keys.")) |
487 |
("tables", _("Overrides option --databases (-B).")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
488 |
("show-progress-size", po::value<uint32_t>(&show_progress_size)->default_value(10000), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
489 |
_("Number of rows before each output progress report (requires --verbose).")) |
1633.5.1
by Vijay Samuel
Merge trunk |
490 |
("verbose,v", po::value<bool>(&verbose)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
491 |
_("Print info about the various stages.")) |
492 |
("version,V", _("Output version information and exit.")) |
|
493 |
("skip-comments", _("Turn off Comments")) |
|
494 |
("skip-create", _("Turn off create-options")) |
|
495 |
("skip-extended-insert", _("Turn off extended-insert")) |
|
496 |
("skip-dump-date", _( "Turn off dump date at the end of the output")) |
|
497 |
("no-defaults", _("Do not read from the configuration files")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
498 |
;
|
499 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
500 |
po::options_description dump_options(_("Options specific to the drizzle client")); |
1633.5.1
by Vijay Samuel
Merge trunk |
501 |
dump_options.add_options() |
502 |
("add-drop-database", po::value<bool>(&opt_drop_database)->default_value(false)->zero_tokens(), |
|
2068.4.1
by Andrew Hutchings
Fix intl domain |
503 |
_("Add a 'DROP DATABASE' before each create.")) |
504 |
("skip-drop-table", _("Do not add a 'drop table' before each create.")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
505 |
("compact", po::value<bool>(&opt_compact)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
506 |
_("Give less verbose output (useful for debugging). Disables structure comments and header/footer constructs. Enables options --skip-add-drop-table --no-set-names --skip-disable-keys")) |
1633.5.1
by Vijay Samuel
Merge trunk |
507 |
("databases,B", po::value<bool>(&opt_databases)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
508 |
_("To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.")) |
1751.4.18
by Andrew Hutchings
Make some command line options work again |
509 |
("skip-disable-keys,K", |
2068.4.1
by Andrew Hutchings
Fix intl domain |
510 |
_("'ALTER TABLE tb_name DISABLE KEYS;' and 'ALTER TABLE tb_name ENABLE KEYS;' will not be put in the output.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
511 |
("ignore-table", po::value<string>(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
512 |
_("Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g. --ignore-table=database.table")) |
1633.5.1
by Vijay Samuel
Merge trunk |
513 |
("insert-ignore", po::value<bool>(&opt_ignore)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
514 |
_("Insert rows with INSERT IGNORE.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
515 |
("no-autocommit", po::value<bool>(&opt_autocommit)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
516 |
_("Wrap a table's data in START TRANSACTION/COMMIT statements.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
517 |
("no-create-db,n", po::value<bool>(&opt_create_db)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
518 |
_("'CREATE DATABASE IF NOT EXISTS db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
519 |
("no-data,d", po::value<bool>(&opt_no_data)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
520 |
_("No row information.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
521 |
("replace", po::value<bool>(&opt_replace_into)->default_value(false)->zero_tokens(), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
522 |
_("Use REPLACE INTO instead of INSERT INTO.")) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
523 |
("destination-type", po::value<string>()->default_value("stdout"), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
524 |
_("Where to send output to (stdout|database")) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
525 |
("destination-host", po::value<string>(&opt_destination_host)->default_value("localhost"), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
526 |
_("Hostname for destination db server (requires --destination-type=database)")) |
1865.3.1
by Andrew Hutchings
Make port 4427 the default for client apps |
527 |
("destination-port", po::value<uint16_t>(&opt_destination_port)->default_value(4427), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
528 |
_("Port number for destination db server (requires --destination-type=database)")) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
529 |
("destination-user", po::value<string>(&opt_destination_user), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
530 |
_("User name for destination db server (resquires --destination-type=database)")) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
531 |
("destination-password", po::value<string>(&opt_destination_password), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
532 |
_("Password for destination db server (requires --destination-type=database)")) |
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
533 |
("destination-database", po::value<string>(&opt_destination_database), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
534 |
_("The database in the destination db server (requires --destination-type=database, not for use with --all-databases)")) |
2121.8.1
by Andrew Hutchings
Add option --my-data-is-mangled to drizzledump to prevent further corruption by retrieving UTF8 data stored in a non-UTF8 table during a MySQL -> Drizzle conversion |
535 |
("my-data-is-mangled", po::value<bool>(&opt_data_is_mangled)->default_value(false)->zero_tokens(), |
536 |
_("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
537 |
;
|
538 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
539 |
po::options_description client_options(_("Options specific to the client")); |
1633.5.1
by Vijay Samuel
Merge trunk |
540 |
client_options.add_options() |
541 |
("host,h", po::value<string>(¤t_host)->default_value("localhost"), |
|
2068.4.1
by Andrew Hutchings
Fix intl domain |
542 |
_("Connect to host.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
543 |
("password,P", po::value<string>(&password)->default_value(PASSWORD_SENTINEL), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
544 |
_("Password to use when connecting to server. If password is not given it's solicited on the tty.")) |
1633.5.1
by Vijay Samuel
Merge trunk |
545 |
("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
546 |
_("Port number to use for connection.")) |
2318.4.7
by Olaf van der Spek
Refactor |
547 |
("user,u", po::value<string>(¤t_user)->default_value(UserDetect().getUser()), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
548 |
_("User for login if not current user.")) |
1745.2.1
by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar. |
549 |
("protocol",po::value<string>(&opt_protocol)->default_value("mysql"), |
2068.4.1
by Andrew Hutchings
Fix intl domain |
550 |
_("The protocol of connection (mysql or drizzle).")) |
1633.5.1
by Vijay Samuel
Merge trunk |
551 |
;
|
552 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
553 |
po::options_description hidden_options(_("Hidden Options")); |
1633.5.1
by Vijay Samuel
Merge trunk |
554 |
hidden_options.add_options() |
2068.4.1
by Andrew Hutchings
Fix intl domain |
555 |
("database-used", po::value<vector<string> >(), _("Used to select the database")) |
556 |
("Table-used", po::value<vector<string> >(), _("Used to select the tables")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
557 |
;
|
558 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
559 |
po::options_description all_options(_("Allowed Options + Hidden Options")); |
1633.5.1
by Vijay Samuel
Merge trunk |
560 |
all_options.add(commandline_options).add(dump_options).add(client_options).add(hidden_options); |
561 |
||
2068.4.1
by Andrew Hutchings
Fix intl domain |
562 |
po::options_description long_options(_("Allowed Options")); |
1633.5.1
by Vijay Samuel
Merge trunk |
563 |
long_options.add(commandline_options).add(dump_options).add(client_options); |
564 |
||
565 |
std::string system_config_dir_dump(SYSCONFDIR); |
|
566 |
system_config_dir_dump.append("/drizzle/drizzledump.cnf"); |
|
567 |
||
568 |
std::string system_config_dir_client(SYSCONFDIR); |
|
569 |
system_config_dir_client.append("/drizzle/client.cnf"); |
|
570 |
||
1671.2.1
by Vijay Samuel
Merge new user config file processing system. |
571 |
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config")); |
572 |
||
1921.3.1
by Andrew Hutchings
Using '~' to represent home is a shell standard, POSIX functions do not understand it. So for home config file loading substitute it for env variable $HOME if possible (also a POSIX standard) |
573 |
if (user_config_dir.compare(0, 2, "~/") == 0) |
574 |
{
|
|
575 |
char *homedir; |
|
576 |
homedir= getenv("HOME"); |
|
577 |
if (homedir != NULL) |
|
578 |
user_config_dir.replace(0, 1, homedir); |
|
579 |
}
|
|
580 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
581 |
po::positional_options_description p; |
582 |
p.add("database-used", 1); |
|
1633.5.5
by Vijay Samuel
Merge fix for --tab |
583 |
p.add("Table-used",-1); |
1633.5.1
by Vijay Samuel
Merge trunk |
584 |
|
585 |
md_result_file= stdout; |
|
586 |
||
587 |
po::variables_map vm; |
|
588 |
||
1793.3.1
by Andrew Hutchings
Disable boost:po allow_guessing which was making some wrong assumptions |
589 |
// Disable allow_guessing
|
590 |
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing; |
|
591 |
||
592 |
po::store(po::command_line_parser(argc, argv).style(style). |
|
593 |
options(all_options).positional(p). |
|
594 |
extra_parser(parse_password_arg).run(), vm); |
|
1633.5.1
by Vijay Samuel
Merge trunk |
595 |
|
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
596 |
if (! vm.count("no-defaults")) |
1633.5.1
by Vijay Samuel
Merge trunk |
597 |
{
|
1671.2.1
by Vijay Samuel
Merge new user config file processing system. |
598 |
std::string user_config_dir_dump(user_config_dir); |
599 |
user_config_dir_dump.append("/drizzle/drizzledump.cnf"); |
|
600 |
||
601 |
std::string user_config_dir_client(user_config_dir); |
|
602 |
user_config_dir_client.append("/drizzle/client.cnf"); |
|
603 |
||
604 |
ifstream user_dump_ifs(user_config_dir_dump.c_str()); |
|
1633.5.1
by Vijay Samuel
Merge trunk |
605 |
po::store(parse_config_file(user_dump_ifs, dump_options), vm); |
1671.2.1
by Vijay Samuel
Merge new user config file processing system. |
606 |
|
607 |
ifstream user_client_ifs(user_config_dir_client.c_str()); |
|
608 |
po::store(parse_config_file(user_client_ifs, client_options), vm); |
|
609 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
610 |
ifstream system_dump_ifs(system_config_dir_dump.c_str()); |
1671.2.1
by Vijay Samuel
Merge new user config file processing system. |
611 |
po::store(parse_config_file(system_dump_ifs, dump_options), vm); |
1633.5.1
by Vijay Samuel
Merge trunk |
612 |
|
613 |
ifstream system_client_ifs(system_config_dir_client.c_str()); |
|
614 |
po::store(parse_config_file(system_client_ifs, client_options), vm); |
|
615 |
}
|
|
616 |
||
617 |
po::notify(vm); |
|
618 |
||
1720.3.1
by LinuxJedi
Fix for bug #620670: |
619 |
if ((not vm.count("database-used") && not vm.count("Table-used") |
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
620 |
&& not opt_alldbs && path.empty()) |
621 |
|| (vm.count("help")) || vm.count("version")) |
|
1633.5.1
by Vijay Samuel
Merge trunk |
622 |
{
|
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
623 |
printf(_("Drizzledump %s build %s, for %s-%s (%s)\n"), |
624 |
drizzle_version(), VERSION, HOST_VENDOR, HOST_OS, HOST_CPU); |
|
625 |
if (vm.count("version")) |
|
626 |
exit(0); |
|
1720.3.1
by LinuxJedi
Fix for bug #620670: |
627 |
puts(""); |
628 |
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n")); |
|
629 |
puts(_("Dumps definitions and data from a Drizzle database server")); |
|
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
630 |
printf(_("Usage: %s [OPTIONS] database [tables]\n"), progname.c_str()); |
1633.5.1
by Vijay Samuel
Merge trunk |
631 |
printf(_("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"), |
1729.3.2
by LinuxJedi
Further cleanups based on Monty's comments (also revert a couple of things) |
632 |
progname.c_str()); |
633 |
printf(_("OR %s [OPTIONS] --all-databases [OPTIONS]\n"), progname.c_str()); |
|
1720.3.1
by LinuxJedi
Fix for bug #620670: |
634 |
cout << long_options; |
635 |
if (vm.count("help")) |
|
636 |
exit(0); |
|
637 |
else
|
|
638 |
exit(1); |
|
1633.5.1
by Vijay Samuel
Merge trunk |
639 |
}
|
640 |
||
1757.5.1
by Andrew Hutchings
Rework the boolean options so that true-by-default options change to --disable-option. |
641 |
/* Inverted Booleans */
|
642 |
||
2252.1.28
by Olaf van der Spek
Refactor Program Options usage |
643 |
opt_drop= not vm.count("skip-drop-table"); |
644 |
opt_comments= not vm.count("skip-comments"); |
|
645 |
extended_insert= not vm.count("skip-extended-insert"); |
|
646 |
opt_dump_date= not vm.count("skip-dump-date"); |
|
647 |
opt_disable_keys= not vm.count("skip-disable-keys"); |
|
648 |
opt_quoted= not vm.count("skip-quote-names"); |
|
1757.5.1
by Andrew Hutchings
Rework the boolean options so that true-by-default options change to --disable-option. |
649 |
|
1745.2.1
by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar. |
650 |
if (vm.count("protocol")) |
651 |
{
|
|
2318.7.21
by Olaf van der Spek
Use boost::to_lower |
652 |
boost::to_lower(opt_protocol); |
1745.2.1
by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar. |
653 |
if (not opt_protocol.compare("mysql")) |
654 |
use_drizzle_protocol=false; |
|
655 |
else if (not opt_protocol.compare("drizzle")) |
|
656 |
use_drizzle_protocol=true; |
|
657 |
else
|
|
658 |
{
|
|
659 |
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl; |
|
660 |
exit(-1); |
|
661 |
}
|
|
662 |
}
|
|
663 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
664 |
if (vm.count("port")) |
665 |
{
|
|
666 |
/* If the port number is > 65535 it is not a valid port
|
|
667 |
* This also helps with potential data loss casting unsigned long to a
|
|
668 |
* uint32_t.
|
|
669 |
*/
|
|
670 |
if (opt_drizzle_port > 65535) |
|
671 |
{
|
|
672 |
fprintf(stderr, _("Value supplied for port is not valid.\n")); |
|
673 |
exit(-1); |
|
674 |
}
|
|
675 |
}
|
|
676 |
||
2252.1.28
by Olaf van der Spek
Refactor Program Options usage |
677 |
if (vm.count("password")) |
1633.5.1
by Vijay Samuel
Merge trunk |
678 |
{
|
679 |
if (!opt_password.empty()) |
|
680 |
opt_password.erase(); |
|
681 |
if (password == PASSWORD_SENTINEL) |
|
682 |
{
|
|
683 |
opt_password= ""; |
|
684 |
}
|
|
685 |
else
|
|
686 |
{
|
|
687 |
opt_password= password; |
|
688 |
tty_password= false; |
|
689 |
}
|
|
690 |
}
|
|
691 |
else
|
|
692 |
{
|
|
693 |
tty_password= true; |
|
694 |
}
|
|
695 |
||
696 |
if (! path.empty()) |
|
697 |
{
|
|
698 |
opt_disable_keys= 0; |
|
699 |
}
|
|
700 |
||
701 |
if (vm.count("skip-opt")) |
|
702 |
{
|
|
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
703 |
extended_insert= opt_drop= create_options= 0; |
704 |
opt_disable_keys= 0; |
|
1633.5.1
by Vijay Samuel
Merge trunk |
705 |
}
|
706 |
||
707 |
if (opt_compact) |
|
708 |
{
|
|
1799.7.6
by Andrew Hutchings
Fix comments appearing in test cases |
709 |
opt_comments= opt_drop= opt_disable_keys= 0; |
1633.5.1
by Vijay Samuel
Merge trunk |
710 |
}
|
711 |
||
712 |
if (vm.count("opt")) |
|
713 |
{
|
|
1799.7.2
by Andrew Hutchings
Clean up some drizzledump options |
714 |
extended_insert= opt_drop= create_options= 1; |
715 |
opt_disable_keys= 1; |
|
1633.5.1
by Vijay Samuel
Merge trunk |
716 |
}
|
717 |
||
718 |
if (vm.count("tables")) |
|
719 |
{
|
|
720 |
opt_databases= false; |
|
721 |
}
|
|
722 |
||
723 |
if (vm.count("ignore-table")) |
|
724 |
{
|
|
725 |
if (!strchr(vm["ignore-table"].as<string>().c_str(), '.')) |
|
726 |
{
|
|
727 |
fprintf(stderr, _("Illegal use of option --ignore-table=<database>.<table>\n")); |
|
728 |
exit(EXIT_ARGUMENT_INVALID); |
|
729 |
}
|
|
730 |
string tmpptr(vm["ignore-table"].as<string>()); |
|
731 |
ignore_table.insert(tmpptr); |
|
732 |
}
|
|
1757.5.2
by Andrew Hutchings
Fix broke drizzledump option and tests |
733 |
|
734 |
if (vm.count("skip-create")) |
|
735 |
{
|
|
736 |
opt_create_db= opt_no_create_info= create_options= false; |
|
737 |
}
|
|
738 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
739 |
exit_code= get_options(); |
1
by brian
clean slate |
740 |
if (exit_code) |
741 |
{
|
|
53.2.4
by Monty Taylor
Changes so that client/ builds cleanly with no warnings. |
742 |
free_resources(); |
1
by brian
clean slate |
743 |
exit(exit_code); |
744 |
}
|
|
1802.6.1
by Andrew Hutchings
Add better error handling and exception handling for database connect |
745 |
try
|
746 |
{
|
|
747 |
db_connection = new DrizzleDumpConnection(current_host, opt_drizzle_port, |
|
748 |
current_user, opt_password, use_drizzle_protocol); |
|
749 |
}
|
|
1966.3.1
by Monty Taylor
Use std::exception instead of catch(...) |
750 |
catch (std::exception&) |
1802.6.1
by Andrew Hutchings
Add better error handling and exception handling for database connect |
751 |
{
|
752 |
maybe_exit(EX_DRIZZLEERR); |
|
753 |
}
|
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
754 |
|
2187.3.2
by Andrew Hutchings
Separate the server detection functions into a .h file |
755 |
if ((db_connection->getServerType() == ServerDetect::SERVER_MYSQL_FOUND) and (not opt_data_is_mangled)) |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
756 |
db_connection->queryNoResult("SET NAMES 'utf8'"); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
757 |
|
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
758 |
if (vm.count("destination-type")) |
759 |
{
|
|
760 |
string tmp_destination(vm["destination-type"].as<string>()); |
|
761 |
if (tmp_destination.compare("database") == 0) |
|
762 |
opt_destination= DESTINATION_DB; |
|
763 |
else if (tmp_destination.compare("stdout") == 0) |
|
764 |
opt_destination= DESTINATION_STDOUT; |
|
765 |
else
|
|
766 |
exit(EXIT_ARGUMENT_INVALID); |
|
767 |
}
|
|
768 |
||
769 |
||
1633.5.1
by Vijay Samuel
Merge trunk |
770 |
if (path.empty() && vm.count("database-used")) |
771 |
{
|
|
772 |
string database_used= *vm["database-used"].as< vector<string> >().begin(); |
|
1751.4.23
by Andrew Hutchings
Fix various bugs |
773 |
write_header((char *)database_used.c_str()); |
1633.5.1
by Vijay Samuel
Merge trunk |
774 |
}
|
1
by brian
clean slate |
775 |
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
776 |
if ((opt_lock_all_tables) && do_flush_tables_read_lock()) |
1
by brian
clean slate |
777 |
goto err; |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
778 |
if (opt_single_transaction && start_transaction()) |
1407
by Brian Aker
Merge Siddharth, ran formatting across it. |
779 |
goto err; |
1059.1.1
by patg
Removed all master/slave-specific code in drizzledump |
780 |
if (opt_lock_all_tables) |
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
781 |
db_connection->queryNoResult("FLUSH LOGS"); |
1
by brian
clean slate |
782 |
|
783 |
if (opt_alldbs) |
|
784 |
{
|
|
785 |
dump_all_databases(); |
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
786 |
dump_all_tables(); |
1
by brian
clean slate |
787 |
}
|
2252.1.28
by Olaf van der Spek
Refactor Program Options usage |
788 |
if (vm.count("database-used") && vm.count("Table-used") && not opt_databases) |
1
by brian
clean slate |
789 |
{
|
1633.5.1
by Vijay Samuel
Merge trunk |
790 |
string database_used= *vm["database-used"].as< vector<string> >().begin(); |
1
by brian
clean slate |
791 |
/* Only one database and selected table(s) */
|
1633.5.5
by Vijay Samuel
Merge fix for --tab |
792 |
dump_selected_tables(database_used, vm["Table-used"].as< vector<string> >()); |
1633.5.1
by Vijay Samuel
Merge trunk |
793 |
}
|
794 |
||
2252.1.28
by Olaf van der Spek
Refactor Program Options usage |
795 |
if (vm.count("Table-used") && opt_databases) |
1633.5.1
by Vijay Samuel
Merge trunk |
796 |
{
|
797 |
vector<string> database_used= vm["database-used"].as< vector<string> >(); |
|
1633.5.5
by Vijay Samuel
Merge fix for --tab |
798 |
vector<string> table_used= vm["Table-used"].as< vector<string> >(); |
1633.5.1
by Vijay Samuel
Merge trunk |
799 |
|
800 |
for (vector<string>::iterator it= table_used.begin(); |
|
801 |
it != table_used.end(); |
|
802 |
++it) |
|
803 |
{
|
|
804 |
database_used.insert(database_used.end(), *it); |
|
805 |
}
|
|
1976.4.4
by Andrew Hutchings
Make --databases option work again |
806 |
|
1633.5.1
by Vijay Samuel
Merge trunk |
807 |
dump_databases(database_used); |
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
808 |
dump_all_tables(); |
1
by brian
clean slate |
809 |
}
|
1976.4.5
by Andrew Hutchings
Removed something I shouldn't have by accident |
810 |
|
2252.1.28
by Olaf van der Spek
Refactor Program Options usage |
811 |
if (vm.count("database-used") && not vm.count("Table-used")) |
1976.4.5
by Andrew Hutchings
Removed something I shouldn't have by accident |
812 |
{
|
813 |
dump_databases(vm["database-used"].as< vector<string> >()); |
|
814 |
dump_all_tables(); |
|
815 |
}
|
|
816 |
||
1751.4.21
by Andrew Hutchings
Add database destination settings and connect it all up |
817 |
if (opt_destination == DESTINATION_STDOUT) |
818 |
generate_dump(); |
|
819 |
else
|
|
820 |
generate_dump_db(); |
|
1751.4.3
by Andrew Hutchings
Rip out tons of code which I'll probably put back cleaner later |
821 |
|
1
by brian
clean slate |
822 |
/* ensure dumped data flushed */
|
823 |
if (md_result_file && fflush(md_result_file)) |
|
824 |
{
|
|
825 |
if (!first_error) |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
826 |
first_error= EX_DRIZZLEERR; |
1
by brian
clean slate |
827 |
goto err; |
828 |
}
|
|
829 |
||
830 |
/*
|
|
831 |
No reason to explicitely COMMIT the transaction, neither to explicitely
|
|
832 |
UNLOCK TABLES: these will be automatically be done by the server when we
|
|
833 |
disconnect now. Saves some code here, some network trips, adds nothing to
|
|
834 |
server.
|
|
835 |
*/
|
|
836 |
err: |
|
1751.4.20
by Andrew Hutchings
Add database connection class and the start of a database output ostream |
837 |
delete db_connection; |
1883.3.1
by Andrew Hutchings
Cleanup drizzledump and drizzle for cppcheck |
838 |
delete destination_connection; |
1633.5.1
by Vijay Samuel
Merge trunk |
839 |
if (path.empty()) |
1
by brian
clean slate |
840 |
write_footer(md_result_file); |
841 |
free_resources(); |
|
842 |
||
843 |
if (stderror_file) |
|
844 |
fclose(stderror_file); |
|
1633.5.1
by Vijay Samuel
Merge trunk |
845 |
}
|
1
by brian
clean slate |
846 |
|
1633.5.1
by Vijay Samuel
Merge trunk |
847 |
catch(exception &err) |
848 |
{
|
|
1633.5.6
by Vijay Samuel
Merge fixes requested by Padraig. |
849 |
cerr << err.what() << endl; |
1633.5.1
by Vijay Samuel
Merge trunk |
850 |
}
|
851 |
||
1
by brian
clean slate |
852 |
return(first_error); |
853 |
} /* main */ |