Skip to content

Commit bba0b97

Browse files
authored
Merge branch 'master' into num_snaps
2 parents 0ea3fcd + cecb21f commit bba0b97

21 files changed

+813
-272
lines changed

CMakeLists.txt

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 2.6)
22
project(mydumper)
3-
set(VERSION 0.10.0)
3+
set(VERSION 0.10.6)
44
set(ARCHIVE_NAME "${CMAKE_PROJECT_NAME}-${VERSION}")
55

66
#Required packages
@@ -32,15 +32,14 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DI
3232

3333

3434
if (WITH_BINLOG)
35-
36-
add_executable(mydumper mydumper.c binlog.c server_detect.c g_unix_signal.c connection.c getPassword.c)
35+
add_executable(mydumper mydumper.c binlog.c server_detect.c g_unix_signal.c connection.c getPassword.c logging.c set_verbose.c)
3736
else (WITH_BINLOG)
38-
add_executable(mydumper mydumper.c server_detect.c g_unix_signal.c connection.c getPassword.c)
37+
add_executable(mydumper mydumper.c server_detect.c g_unix_signal.c connection.c getPassword.c logging.c set_verbose.c)
3938
endif (WITH_BINLOG)
40-
target_link_libraries(mydumper ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${GIO2_LIBRARIES} ${GOBJECT2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES} stdc++)
39+
target_link_libraries(mydumper ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${GIO2_LIBRARIES} ${GOBJECT2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES} stdc++ m)
4140

4241

43-
add_executable(myloader myloader.c connection.c getPassword.c)
42+
add_executable(myloader myloader.c connection.c getPassword.c logging.c set_verbose.c)
4443
target_link_libraries(myloader ${MYSQL_LIBRARIES} ${GLIB2_LIBRARIES} ${GTHREAD2_LIBRARIES} ${PCRE_PCRE_LIBRARY} ${ZLIB_LIBRARIES} stdc++)
4544

4645
INSTALL(TARGETS mydumper myloader

README.md

+67-13
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,84 @@
55
* Consistency - maintains snapshot across all threads, provides accurate master and slave log positions, etc
66
* Manageability - supports PCRE for specifying database and tables inclusions and exclusions
77

8+
## Dependencies for building mydumper
9+
10+
One needs to install development tools:
11+
* Ubuntu or Debian:
12+
```
13+
apt-get install cmake g++ git
14+
```
15+
* Fedora, RedHat and CentOS:
16+
```
17+
yum install -y cmake gcc gcc-c++ git make
18+
```
19+
* MacOSX:
20+
```
21+
port install pkgconfig cmake
22+
```
23+
One needs to install development versions of GLib, ZLib and PCRE:
24+
* Ubuntu or Debian:
25+
```
26+
apt-get install libglib2.0-dev zlib1g-dev libpcre3-dev libssl-dev
27+
```
28+
* Fedora, RedHat and CentOS:
29+
```
30+
yum install -y glib2-devel mysql-devel openssl-devel pcre-devel zlib-devel
31+
```
32+
* openSUSE:
33+
```
34+
zypper install glib2-devel libmysqlclient-devel pcre-devel zlib-devel
35+
```
36+
* MacOSX: port install glib2 pcre
37+
One needs to install MySQL/Percona/MariaDB development versions:
38+
* Ubuntu or Debian:
39+
```
40+
apt-get install libmysqlclient-dev
41+
apt-get install libperconaserverclient20-dev
42+
apt-get install libmariadbclient-dev
43+
```
44+
* Fedora, RedHat and CentOS:
45+
```
46+
yum install -y mysql-devel
47+
yum install -y Percona-Server-devel-57
48+
yum install -y mariadb-devel
49+
```
50+
CentOS 7 comes by default with MariaDB 5.5 libraries which are very old.
51+
It might be better to download a newer version of these libraries (MariaDB, MySQL, Percona etc).
52+
* openSUSE:
53+
```
54+
zypper install libmysqlclient-devel
55+
```
56+
* MacOSX: port install mysql5
57+
(You may want to run 'port select mysql mysql5' afterwards)
58+
59+
# How to use mydumper
60+
61+
See [Usage](docs/mydumper_usage.rst)
62+
863
## How to install mydumper/myloader?
964

1065
First get the correct url from the [releases section](https://github.com/maxbube/mydumper/releases) then:
1166

1267
### RedHat / Centos
1368

1469
```bash
15-
yum install https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper-0.9.5-1.el7.x86_64.rpm
70+
yum install https://github.com/maxbube/mydumper/releases/download/v0.10.5/mydumper-0.10.5-1.el7.x86_64.rpm
71+
yum install https://github.com/maxbube/mydumper/releases/download/v0.10.5/mydumper-0.10.5-1.el8.x86_64.rpm
1672
```
1773

1874
### Ubuntu / Debian
1975

2076
```bash
21-
wget https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper_0.9.5-1.xenial_amd64.deb
22-
dpkg -i mydumper_0.9.5-1.xenial_amd64.deb
77+
wget https://github.com/maxbube/mydumper/releases/download/v0.10.5/mydumper_0.10.5-1.$(lsb_release -cs)_amd64.deb
78+
dpkg -i mydumper_0.10.5-1.$(lsb_release -cs)_amd64.deb
79+
```
80+
81+
### OSX
82+
By using [Homebrew](https://brew.sh/)
83+
84+
```bash
85+
brew install mydumper
2386
```
2487

2588
## How to build it?
@@ -31,15 +94,6 @@ cmake .
3194
make
3295
```
3396

34-
One needs to install development versions of required libaries (MySQL, GLib, ZLib, PCRE):
35-
NOTE: you must use the correspondent mysql devel package.
36-
37-
* Ubuntu or Debian: apt-get install libglib2.0-dev libmysqlclient15-dev zlib1g-dev libpcre3-dev libssl-dev
38-
* Fedora, RedHat and CentOS: yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel
39-
* openSUSE: zypper install glib2-devel libmysqlclient-devel pcre-devel zlib-devel
40-
* MacOSX: port install glib2 mysql5 pcre pkgconfig cmake
41-
(You may want to run 'port select mysql mysql5' afterwards)
42-
4397
One has to make sure, that pkg-config, mysql_config, pcre-config are all in $PATH
4498

4599
Binlog dump is disabled by default to compile with it you need to add -DWITH_BINLOG=ON to cmake options
@@ -51,7 +105,7 @@ To build against mysql libs < 5.7 you need to disable SSL adding -DWITH_SSL=OFF
51105
This is all done following best MySQL practices and traditions:
52106

53107
* As a precaution, slow running queries on the server either abort the dump, or get killed
54-
* Global write lock is acquired ("FLUSH TABLES WITH READ LOCK")
108+
* Global read lock is acquired ("FLUSH TABLES WITH READ LOCK")
55109
* Various metadata is read ("SHOW SLAVE STATUS","SHOW MASTER STATUS")
56110
* Other threads connect and establish snapshots ("START TRANSACTION WITH CONSISTENT SNAPSHOT")
57111
** On pre-4.1.8 it creates dummy InnoDB table, and reads from it.

binlog.c

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <zlib.h>
3030
#include "mydumper.h"
3131
#include "binlog.h"
32+
#include "set_verbose.h"
3233

3334
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
3435

cmake/modules/FindMySQL.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ find_path(MYSQL_INCLUDE_DIR mysql.h
8484
)
8585

8686
set(TMP_MYSQL_LIBRARIES "")
87-
set(CMAKE_FIND_LIBRARY_SUFFIXES .so .a .lib .so.1)
87+
set(CMAKE_FIND_LIBRARY_SUFFIXES .so .lib .so.1 .dylib .a)
8888
foreach(MY_LIB ${MYSQL_ADD_LIBRARIES})
8989
find_library("MYSQL_LIBRARIES_${MY_LIB}" NAMES ${MY_LIB}
9090
HINTS

common.h

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ char *cert = NULL;
2929
char *ca = NULL;
3030
char *capath = NULL;
3131
char *cipher = NULL;
32+
char *tls_version = NULL;
33+
gchar *ssl_mode = NULL;
3234
#endif
3335

3436
gboolean askPassword = FALSE;
@@ -65,6 +67,8 @@ GOptionEntry common_entries[] = {
6567
"Use a specific defaults file", NULL},
6668
#ifdef WITH_SSL
6769
{"ssl", 0, 0, G_OPTION_ARG_NONE, &ssl, "Connect using SSL", NULL},
70+
{"ssl-mode", 0, 0, G_OPTION_ARG_STRING, &ssl_mode,
71+
"Desired security state of the connection to the server: DISABLED, PREFERRED, REQUIRED, VERIFY_CA, VERIFY_IDENTITY", NULL},
6872
{"key", 0, 0, G_OPTION_ARG_STRING, &key, "The path name to the key file",
6973
NULL},
7074
{"cert", 0, 0, G_OPTION_ARG_STRING, &cert,
@@ -77,6 +81,8 @@ GOptionEntry common_entries[] = {
7781
NULL},
7882
{"cipher", 0, 0, G_OPTION_ARG_STRING, &cipher,
7983
"A list of permissible ciphers to use for SSL encryption", NULL},
84+
{"tls-version", 0, 0, G_OPTION_ARG_STRING, &tls_version,
85+
"Which protocols the server permits for encrypted connections", NULL},
8086
#endif
8187
{NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
8288

connection.c

+43-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ extern char *cert;
2828
extern char *ca;
2929
extern char *capath;
3030
extern char *cipher;
31+
extern char *tls_version;
3132
extern gboolean ssl;
33+
extern gchar *ssl_mode;
3234
#endif
3335
extern guint compress_protocol;
3436

@@ -45,11 +47,48 @@ void configure_connection(MYSQL *conn, const char *name) {
4547
unsigned int i;
4648
if (ssl) {
4749
i = SSL_MODE_REQUIRED;
50+
mysql_options(conn, MYSQL_OPT_SSL_MODE, &i);
4851
} else {
49-
i = SSL_MODE_DISABLED;
52+
if (ssl_mode) {
53+
if (g_ascii_strncasecmp(ssl_mode, "DISABLED", 16) == 0) {
54+
i = SSL_MODE_DISABLED;
55+
}
56+
else if (g_ascii_strncasecmp(ssl_mode, "PREFERRED", 16) == 0) {
57+
i = SSL_MODE_PREFERRED;
58+
}
59+
else if (g_ascii_strncasecmp(ssl_mode, "REQUIRED", 16) == 0) {
60+
i = SSL_MODE_REQUIRED;
61+
}
62+
else if (g_ascii_strncasecmp(ssl_mode, "VERIFY_CA", 16) == 0) {
63+
i = SSL_MODE_VERIFY_CA;
64+
}
65+
else if (g_ascii_strncasecmp(ssl_mode, "VERIFY_IDENTITY", 16) == 0) {
66+
i = SSL_MODE_VERIFY_IDENTITY;
67+
}
68+
else {
69+
g_critical("Unsupported ssl-mode specified: %s\n", ssl_mode);
70+
exit(EXIT_FAILURE);
71+
}
72+
mysql_options(conn, MYSQL_OPT_SSL_MODE, &i);
73+
}
74+
}
75+
if (key) {
76+
mysql_options(conn, MYSQL_OPT_SSL_KEY, key);
77+
}
78+
if (cert) {
79+
mysql_options(conn, MYSQL_OPT_SSL_CERT, cert);
80+
}
81+
if (ca) {
82+
mysql_options(conn, MYSQL_OPT_SSL_CA, ca);
83+
}
84+
if (capath) {
85+
mysql_options(conn, MYSQL_OPT_SSL_CAPATH, capath);
86+
}
87+
if (cipher) {
88+
mysql_options(conn, MYSQL_OPT_SSL_CIPHER, cipher);
89+
}
90+
if (tls_version) {
91+
mysql_options(conn, MYSQL_OPT_TLS_VERSION, tls_version);
5092
}
51-
52-
mysql_ssl_set(conn, key, cert, ca, capath, cipher);
53-
mysql_options(conn, MYSQL_OPT_SSL_MODE, &i);
5493
#endif
5594
}

docs/_build/conf.py.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ html_theme = 'default'
120120
# Add any paths that contain custom static files (such as style sheets) here,
121121
# relative to this directory. They are copied after the builtin static files,
122122
# so a file named "default.css" will overwrite the builtin "default.css".
123-
html_static_path = ['@CMAKE_CURRENT_SOURCE_DIR@/_static']
123+
html_static_path = ['@CMAKE_CURRENT_SOURCE_DIR@/html/_static']
124124

125125
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
126126
# using the given strftime format.

docs/files.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Where 'chunk' is a number padded with up to 5 zeros.
3636

3737
Table Schemas
3838
-------------
39-
When the :option:`--schemas <mydumper --schemas>` option is used mydumper will
39+
As long as the :option:`--no-schemas <mydumper --no-schemas>` option is not specified, mydumper will
4040
create a file for the schema of every table it is writing data for. The files
4141
for this are in the following format::
4242

docs/mydumper_usage.rst

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ The :program:`mydumper` tool has several available options:
3535
.. option:: --defaults-file
3636

3737
Use the given option file. If the file does not exist or is otherwise inaccessible, no failure occurs
38+
39+
Its possible to authenticate via --defaults-file.
40+
A section [mydumper]/[myloader] or [client] is needed for authentication
41+
42+
[mydumper]
43+
user=
44+
password=
3845

3946
.. option:: --host, -h
4047

@@ -114,6 +121,10 @@ The :program:`mydumper` tool has several available options:
114121

115122
Comma separated list of storage engines to ignore
116123

124+
.. option:: --insert-ignore, -N
125+
126+
Dump rows with INSERT IGNORE INTO instead of INSERT INTO
127+
117128
.. option:: --no-schemas, -m
118129

119130
Do not dump schemas with the data
@@ -138,6 +149,14 @@ The :program:`mydumper` tool has several available options:
138149

139150
Do not dump views
140151

152+
.. option:: --long-query-retries
153+
154+
Retry checking for long queries, default 0 (do not retry)
155+
156+
.. option:: --long-query-retry-interval
157+
158+
Time to wait before retrying the long query check in seconds, default 60
159+
141160
.. option:: --long-query-guard, -l
142161

143162
Timeout for long query execution in seconds, default 60

logging.c

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
This program is free software: you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation, either version 3 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
15+
Authors: Domas Mituzas, Facebook ( domas at fb dot com )
16+
Mark Leith, Oracle Corporation (mark dot leith at oracle
17+
dot com) Andrew Hutchings, SkySQL (andrew at skysql dot com)
18+
19+
*/
20+
21+
#include <unistd.h>
22+
#include <stdio.h>
23+
#include <string.h>
24+
#include <glib.h>
25+
#include <stdlib.h>
26+
#include <stdarg.h>
27+
#include <errno.h>
28+
#include <time.h>
29+
#include <zlib.h>
30+
#include <pcre.h>
31+
#include <signal.h>
32+
#include <glib/gstdio.h>
33+
34+
gchar *logfile;
35+
FILE *logoutfile;
36+
37+
void no_log(const gchar *log_domain, GLogLevelFlags log_level,
38+
const gchar *message, gpointer user_data) {
39+
(void)log_domain;
40+
(void)log_level;
41+
(void)message;
42+
(void)user_data;
43+
}
44+
45+
void write_log_file(const gchar *log_domain, GLogLevelFlags log_level,
46+
const gchar *message, gpointer user_data) {
47+
(void)log_domain;
48+
(void)user_data;
49+
50+
gchar date[20];
51+
time_t rawtime;
52+
struct tm timeinfo;
53+
54+
time(&rawtime);
55+
localtime_r(&rawtime, &timeinfo);
56+
strftime(date, 20, "%Y-%m-%d %H:%M:%S", &timeinfo);
57+
58+
GString *message_out = g_string_new(date);
59+
if (log_level & G_LOG_LEVEL_DEBUG) {
60+
g_string_append(message_out, " [DEBUG] - ");
61+
} else if ((log_level & G_LOG_LEVEL_INFO) ||
62+
(log_level & G_LOG_LEVEL_MESSAGE)) {
63+
g_string_append(message_out, " [INFO] - ");
64+
} else if (log_level & G_LOG_LEVEL_WARNING) {
65+
g_string_append(message_out, " [WARNING] - ");
66+
} else if ((log_level & G_LOG_LEVEL_ERROR) ||
67+
(log_level & G_LOG_LEVEL_CRITICAL)) {
68+
g_string_append(message_out, " [ERROR] - ");
69+
}
70+
71+
g_string_append_printf(message_out, "%s\n", message);
72+
if (write(fileno(logoutfile), message_out->str, message_out->len) <= 0) {
73+
fprintf(stderr, "Cannot write to log file with error %d. Exiting...",
74+
errno);
75+
}
76+
g_string_free(message_out, TRUE);
77+
}

0 commit comments

Comments
 (0)