maatkit-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Changelog +0 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +26 -0
  4. data/lib/maatkit-ruby.rb +11 -0
  5. data/lib/maatkit-ruby/mk-archiver.rb +473 -0
  6. data/lib/maatkit-ruby/mk-checksum-filter.rb +122 -0
  7. data/lib/maatkit-ruby/mk-deadlock-logger.rb +223 -0
  8. data/lib/maatkit-ruby/mk-duplicate-key-checker.rb +239 -0
  9. data/lib/maatkit-ruby/mk-error-log.rb +240 -0
  10. data/lib/maatkit-ruby/mk-fifo-split.rb +130 -0
  11. data/lib/maatkit-ruby/mk-find.rb +137 -0
  12. data/lib/maatkit-ruby/mk-heartbeat.rb +300 -0
  13. data/lib/maatkit-ruby/mk-index-usage.rb +164 -0
  14. data/lib/maatkit-ruby/mk-kill.rb +124 -0
  15. data/lib/maatkit-ruby/mk-loadavg.rb +313 -0
  16. data/lib/maatkit-ruby/mk-log-player.rb +316 -0
  17. data/lib/maatkit-ruby/mk-merge-mqd-results.rb +248 -0
  18. data/lib/maatkit-ruby/mk-parallel-dump.rb +400 -0
  19. data/lib/maatkit-ruby/mk-parallel-restore.rb +133 -0
  20. data/lib/maatkit-ruby/mk-profile-compact.rb +87 -0
  21. data/lib/maatkit-ruby/mk-purge-logs.rb +99 -0
  22. data/lib/maatkit-ruby/mk-query-advisor.rb +105 -0
  23. data/lib/maatkit-ruby/mk-query-digest.rb +149 -0
  24. data/lib/maatkit-ruby/mk-query-profiler.rb +106 -0
  25. data/lib/maatkit-ruby/mk-show-grants.rb +103 -0
  26. data/lib/maatkit-ruby/mk-slave-delay.rb +102 -0
  27. data/lib/maatkit-ruby/mk-slave-find.rb +98 -0
  28. data/lib/maatkit-ruby/mk-slave-move.rb +99 -0
  29. data/lib/maatkit-ruby/mk-slave-prefetch.rb +124 -0
  30. data/lib/maatkit-ruby/mk-slave-restart.rb +116 -0
  31. data/lib/maatkit-ruby/mk-table-checksum.rb +151 -0
  32. data/lib/maatkit-ruby/mk-table-sync.rb +468 -0
  33. data/lib/maatkit-ruby/mk-upgrade.rb +118 -0
  34. data/lib/maatkit-ruby/mk-variable-advisor.rb +99 -0
  35. data/lib/maatkit-ruby/mk-visual-explain.rb +98 -0
  36. data/lib/maatkit-ruby/version.rb +17 -0
  37. data/setup.rb +1585 -0
  38. data/test/test_helper.rb +2 -0
  39. data/test/test_maatkit_ruby.rb +11 -0
  40. metadata +105 -0
@@ -0,0 +1,248 @@
1
+ # = maatkit-ruby - A maatkit gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/maatkit-ruby
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # Merge multiple mk-query-digest reports into one.
10
+ #
11
+ # Maatkit::MergeMqdResults.new( array, str, array)
12
+ #
13
+ class Maatkit::MergeMqdResults
14
+
15
+ #
16
+ # Prompt for a password when connecting to MySQL.
17
+ attr_accessor :ask_pass # FALSE
18
+
19
+ #
20
+ # short form: -A; type: string
21
+ # Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the
22
+ # mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other
23
+ # value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
24
+ attr_accessor :charset # (No # value)
25
+
26
+ #
27
+ # type: Array
28
+ # Read this comma-separated list of config files; if specified, this must be the first option on the
29
+ # command line.
30
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_merge_mqd_results.conf,/home/joel/.maatkit.conf,/home/joel/.mk_merge_mqd_results.conf
31
+
32
+ #
33
+ # short form: -F; type: string
34
+ # Only read mysql options from the given file. You must give an absolute pathname.
35
+ attr_accessor :defaults_file # (No # value)
36
+
37
+ #
38
+ # type: array; default: 5,10
39
+ # Explain items when there are more or fewer than expected.
40
+ # Defines the number of items expected to be seen in the report as controlled by "--limit" and
41
+ # "--outliers". If there are more or fewer items in the report, each one will explain why it was
42
+ # included.
43
+ attr_accessor :expected_range # 5,10
44
+
45
+ #
46
+ # type: DSN
47
+ # Run EXPLAIN for the sample query with this DSN and print results.
48
+ # This causes mk-merge-mqd-results to run EXPLAIN and include the output into the report. For safety,
49
+ # queries that appear to have a subquery that EXPLAIN will execute won't be EXPLAINed. Those are
50
+ # typically "derived table" queries of the form
51
+ # select ... from ( select .... ) der;
52
+ attr_accessor :explain # (No # value)
53
+
54
+ #
55
+ # Add query fingerprints to the standard query analysis report. This is mostly useful for debugging
56
+ # purposes.
57
+ attr_accessor :fingerprints # FALSE
58
+
59
+ #
60
+ # default: yes
61
+ # Print extra information to make analysis easy.
62
+ # This option adds code snippets to make it easy to run SHOW CREATE TABLE and SHOW TABLE STATUS for the
63
+ # query's tables. It also rewrites non-SELECT queries into a SELECT that might be helpful for
64
+ # determining the non-SELECT statement's index usage.
65
+ attr_accessor :for_explain # TRUE
66
+
67
+ #
68
+ # Show help and exit.
69
+ attr_accessor :help # TRUE
70
+
71
+ #
72
+ # short form: -h; type: string
73
+ # Connect to host.
74
+ attr_accessor :host # (No # value)
75
+
76
+ #
77
+ # type: string; default: 95%:20
78
+ # Limit output to the given percentage or count.
79
+ # If the argument is an integer, report only the top N worst queries. If the argument is an integer
80
+ # followed by the "%" sign, report that percentage of the worst queries. If the percentage is followed
81
+ # by a colon and another integer, report the top percentage or the number specified by that integer,
82
+ # whichever comes first.
83
+ # See also "--outliers".
84
+ attr_accessor :limit # 95%:20
85
+
86
+ #
87
+ # type: string; default: Query_time:sum
88
+ # Sort events by this attribute and aggregate function.
89
+ attr_accessor :order_by # Query_time:sum
90
+
91
+ #
92
+ # type: string; default: Query_time:1:10
93
+ # Report outliers by attribute:percentile:count.
94
+ # The syntax of this option is a comma-separated list of colon-delimited strings. The first field is the
95
+ # attribute by which an outlier is defined. The second is a number that is compared to the attribute's
96
+ # 95th percentile. The third is optional, and is compared to the attribute's cnt aggregate. Queries
97
+ # that pass this specification are added to the report, regardless of any limits you specified in
98
+ # "--limit".
99
+ # For example, to report queries whose 95th percentile Query_time is at least 60 seconds and which are
100
+ # seen at least 5 times, use the following argument:
101
+ # --outliers Query_time:60:5
102
+ attr_accessor :outliers # Query_time:1:10
103
+
104
+ #
105
+ # short form: -p; type: string
106
+ # Password to use when connecting.
107
+ attr_accessor :password # (No # value)
108
+
109
+ #
110
+ # short form: -P; type: int
111
+ # Port number to use for connection.
112
+ attr_accessor :port # (No # value)
113
+
114
+ #
115
+ # type: Array; default: rusage,date,files,header,profile,query_report,prepared
116
+ # Print these sections of the query analysis report.
117
+ # SECTION# # PRINTS
118
+ # ============ ==============================================================
119
+ # rusgae# # CPU times and memory usage reported by ps
120
+ # date# # # Current local date and time
121
+ # files# # Input files read/parse
122
+ # header# # Summary of the entire analysis run
123
+ # profile# # Compact table of queries for an at-a-glance view of the report
124
+ # query_report Detailed information about each unique query
125
+ # prepared# Prepared statements
126
+ # The sections are printed in the order specified. The rusage, date, files and header sections are
127
+ # grouped together if specified together; other sections are separted by blank lines.
128
+ attr_accessor :report_format # rusage,date,files,header,profile,query_report,prepared
129
+
130
+ #
131
+ # type: string; default: Query_time
132
+ # Chart the distribution of this attribute's values.
133
+ # The distribution chart is limited to time-based attributes, so charting "Rows_examined", for example,
134
+ # will produce a useless chart.
135
+ attr_accessor :report_histogram # Query_time
136
+
137
+ #
138
+ # type: string; default: wait_timeout=10000
139
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
140
+ # and executed.
141
+ attr_accessor :set_vars # wait_timeout=10000
142
+
143
+ #
144
+ # type: int; default: 1024
145
+ # Shorten long statements in reports.
146
+ # Shortens long statements, replacing the omitted portion with a "/*... omitted ...*/" comment. This
147
+ # applies only to the output in reports, not to information stored other places. It prevents a large
148
+ # statement from causing difficulty in a report. The argument is the preferred length of the shortened
149
+ # statement. Not all statements can be shortened, but very large INSERT and similar statements often
150
+ # can; and so can IN() lists, although only the first such list in the statement will be shortened.
151
+ # If it shortens something beyond recognition, you can find the original statement in the log, at the
152
+ # offset shown in the report header.
153
+ attr_accessor :shorten # 1024
154
+
155
+ #
156
+ # type: Hash
157
+ # Show all values for these attributes.
158
+ # By default mk-query-digest only shows as many of an attribute's value that fit on a single line. This
159
+ # option allows you to specify attributes for which all values will be shown (line width is ignored).
160
+ # This only works for attributes with string values like user, host, db, etc. Multiple attributes can be
161
+ # specified, comma-separated.
162
+ attr_accessor :show_all #
163
+
164
+ #
165
+ # short form: -S; type: string
166
+ # Socket file to use for connection.
167
+ attr_accessor :socket # (No # value)
168
+
169
+ #
170
+ # short form: -u; type: string
171
+ # User for login if not current user.
172
+ attr_accessor :user # (No # value)
173
+
174
+ #
175
+ # Show version and exit.
176
+ attr_accessor :version # FALSE
177
+
178
+ #
179
+ # default: yes
180
+ # Print 0% boolean values in report.
181
+ attr_accessor :zero_bool # TRUE
182
+
183
+ #
184
+ # Sets the executable path, otherwise the environment path will be used.
185
+ #
186
+ attr_accessor :path_to_mk_merge_mqd_results
187
+
188
+ #
189
+ # Returns a new MergeMqdResults Object
190
+ #
191
+ def initialize()
192
+ end
193
+
194
+ #
195
+ # Execute the command
196
+ #
197
+ def start(options = nil)
198
+ tmp = Tempfile.new('tmp')
199
+ command = option_string() + options.to_s + " 2> " + tmp.path
200
+ success = system(command)
201
+ if success
202
+ begin
203
+ while (line = tmp.readline)
204
+ line.chomp
205
+ selected_string = line
206
+ end
207
+ rescue EOFError
208
+ tmp.close
209
+ end
210
+ return selected_string
211
+ else
212
+ tmp.close!
213
+ return success
214
+ end
215
+ end
216
+
217
+ def config
218
+ option_string()
219
+ end
220
+
221
+ private
222
+
223
+ def option_string()
224
+
225
+ unless @path_to_mk_merge_mqd_results
226
+ ostring = "mk-merge-mqd-results "
227
+ else
228
+ ostring = @path_to_mk_merge_mqd_results + " "
229
+ end
230
+
231
+ self.instance_variables.each do |i|
232
+ tmp_value = self.instance_variable_get "#{i}"
233
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
234
+ unless tmp_string == "--path-to-mk-merge-mqd-results"
235
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
236
+ ostring += "#{tmp_string} "
237
+ else
238
+ ostring += "#{tmp_string} #{tmp_value} "
239
+ end
240
+ end
241
+ end
242
+
243
+ return ostring
244
+
245
+ end
246
+
247
+ end
248
+
@@ -0,0 +1,400 @@
1
+ # = maatkit-ruby - A maatkit gem for Ruby
2
+ #
3
+ # Homepage:: http://github.com/jjuliano/maatkit-ruby
4
+ # Author:: Joel Bryan Juliano
5
+ # Copyright:: (cc) 2011 Joel Bryan Juliano
6
+ # License:: MIT
7
+
8
+ #
9
+ # Dump MySQL tables in parallel.
10
+ #
11
+ # Maatkit::ParallelDump.new( array, str, array)
12
+ #
13
+ class Maatkit::ParallelDump
14
+
15
+ #
16
+ # Prompt for a password when connecting to MySQL.
17
+ attr_accessor :ask_pass # FALSE
18
+
19
+ #
20
+ # type: string
21
+ # The base directory in which files will be stored.
22
+ # The default is the current working directory. Each database gets its own directory under the base
23
+ # directory. So if the base directory is "/tmp" and database "foo" is dumped, then the directory
24
+ # "/tmp/foo" is created which contains all the table dump files for "foo".
25
+ attr_accessor :base_dir # /home/joel/maatkit_ruby/lib/maatkit_ruby
26
+
27
+ #
28
+ # default: yes
29
+ # Process tables in descending order of size (biggest to smallest).
30
+ # This strategy gives better parallelization. Suppose there are 8 threads and the last table is huge.
31
+ # We will finish everything else and then be running single-threaded while that one finishes. If that
32
+ # one runs first, then we will have the max number of threads running at a time for as long as possible.
33
+ attr_accessor :biggest_first # TRUE
34
+
35
+ #
36
+ # default: yes
37
+ # Dump the master/slave position.
38
+ # Dump binary log positions from both "SHOW MASTER STATUS" and "SHOW SLAVE STATUS", whichever can be
39
+ # retrieved from the server. The data is dumped to a file named 00_master_data.sql in the "--base-dir".
40
+ # The file also contains details of each table dumped, including the WHERE clauses used to dump it in
41
+ # chunks.
42
+ attr_accessor :bin_log_position # TRUE
43
+
44
+ #
45
+ # short form: -A; type: string
46
+ # Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the
47
+ # mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other
48
+ # value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
49
+ attr_accessor :charset # (No # value)
50
+
51
+ #
52
+ # type: string
53
+ # Number of rows or data size to dump per file.
54
+ # Specifies that the table should be dumped in segments of approximately the size given. The syntax is
55
+ # either a plain integer, which is interpreted as a number of rows per chunk, or an integer with a suffix
56
+ # of G, M, or k, which is interpreted as the size of the data to be dumped in each chunk. See "CHUNKS"
57
+ # for more details.
58
+ attr_accessor :chunk_size # (No # value)
59
+
60
+ #
61
+ # Fetch and buffer results in memory on client.
62
+ # By default this option is not enabled because it causes data to be completely fetched from the server
63
+ # then buffered in-memory on the client. For large dumps this can require a lot of memory
64
+ # Instead, the default (when this option is not specified) is to fetch and dump rows one-by-one from the
65
+ # server. This requires a lot less memory on the client but can keep the tables on the server locked
66
+ # longer.
67
+ # Use this option only if you're sure that the data being dumped is relatively small and the client has
68
+ # sufficient memory. Remember that, if this option is specified, all "--threads" will buffer their
69
+ # results in-memory, so memory consumption can increase by a factor of N "--threads".
70
+ attr_accessor :client_side_buffering # FALSE
71
+
72
+ #
73
+ # type: Array
74
+ # Read this comma-separated list of config files; if specified, this must be the first option on the
75
+ # command line.
76
+ attr_accessor :config # /etc/maatkit/maatkit.conf,/etc/maatkit/mk_parallel_dump.conf,/home/joel/.maatkit.conf,/home/joel/.mk_parallel_dump.conf
77
+
78
+ #
79
+ # Do "--tab" dump in CSV format (implies "--tab").
80
+ # Changes "--tab" options so the dump file is in comma-separated values (CSV) format. The SELECT INTO
81
+ # OUTFILE statement looks like the following, and can be re-loaded with the same options:
82
+ # # SELECT * INTO OUTFILE %D.%N.%6C.txt
83
+ # # FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
84
+ # # LINES TERMINATED BY '\n' FROM %D.%N;
85
+ attr_accessor :csv # FALSE
86
+
87
+ #
88
+ # short form: -d; type: hash
89
+ # Dump only this comma-separated list of databases.
90
+ attr_accessor :databases # (No # value)
91
+
92
+ #
93
+ # type: string
94
+ # Dump only databases whose names match this Perl regex.
95
+ attr_accessor :databases_regex # (No # value)
96
+
97
+ #
98
+ # short form: -F; type: string
99
+ # Only read mysql options from the given file. You must give an absolute pathname.
100
+ attr_accessor :defaults_file # (No # value)
101
+
102
+ #
103
+ # Print commands instead of executing them.
104
+ attr_accessor :dry_run # FALSE
105
+
106
+ #
107
+ # short form: -e; type: hash
108
+ # Dump only tables that use this comma-separated list of storage engines.
109
+ attr_accessor :engines # (No # value)
110
+
111
+ #
112
+ # Use "FLUSH TABLES WITH READ LOCK".
113
+ # This is enabled by default. The lock is taken once, at the beginning of the whole process and is
114
+ # released after all tables have been dumped. If you want to lock only the tables you're dumping, use
115
+ # "--lock-tables".
116
+ attr_accessor :flush_lock # FALSE
117
+
118
+ #
119
+ # Execute "FLUSH LOGS" when getting binlog positions.
120
+ # This option is NOT enabled by default because it causes the MySQL server to rotate its error log,
121
+ # potentially overwriting error messages.
122
+ attr_accessor :flush_log # FALSE
123
+
124
+ #
125
+ # default: yes
126
+ # Compress (gzip) SQL dump files; does not work with "--tab".
127
+ # The IO::Compress::Gzip Perl module is used to compress SQL dump files as they are written to disk. The
128
+ # resulting dump files have a ".gz" extension, like "table.000000.sql.gz". They can be uncompressed with
129
+ # gzip. mk-parallel-restore will automatically uncompress them, too, when restoring.
130
+ # This option does not work with "--tab" because the MySQL server writes the tab dump files directly
131
+ # using "SELECT INTO OUTFILE".
132
+ attr_accessor :gzip # TRUE
133
+
134
+ #
135
+ # Show help and exit.
136
+ attr_accessor :help # TRUE
137
+
138
+ #
139
+ # short form: -h; type: string
140
+ # Connect to host.
141
+ attr_accessor :host # (No # value)
142
+
143
+ #
144
+ # type: Hash
145
+ # Ignore this comma-separated list of databases.
146
+ attr_accessor :ignore_databases #
147
+
148
+ #
149
+ # type: string
150
+ # Ignore databases whose names match this Perl regex.
151
+ attr_accessor :ignore_databases_regex # (No # value)
152
+
153
+ #
154
+ # type: Hash; default: FEDERATED,MRG_MyISAM
155
+ # Do not dump tables that use this comma-separated list of storage engines.
156
+ # The schema file will be dumped as usual. This prevents dumping data for Federated tables and Merge
157
+ # tables.
158
+ attr_accessor :ignore_engines # FEDERATED,MRG_MyISAM
159
+
160
+ #
161
+ # type: Hash
162
+ # Ignore this comma-separated list of table names.
163
+ # Table names may be qualified with the database name.
164
+ attr_accessor :ignore_tables #
165
+
166
+ #
167
+ # type: string
168
+ # Ignore tables whose names match the Perl regex.
169
+ attr_accessor :ignore_tables_regex # (No # value)
170
+
171
+ #
172
+ # Use "LOCK TABLES" (disables "--[no]flush-lock").
173
+ # Disables "--[no]flush-lock" (unless it was explicitly set) and locks tables with "LOCK TABLES READ".
174
+ # The lock is taken and released for every table as it is dumped.
175
+ attr_accessor :lock_tables # FALSE
176
+
177
+ #
178
+ # Dump float types with extra precision for lossless restore (requires "--tab").
179
+ # Wraps these types with a call to "FORMAT()" with 17 digits of precision. According to the comments in
180
+ # Google's patches, this will give lossless dumping and reloading in most cases. (I shamelessly stole
181
+ # this technique from them. I don't know enough about floating-point math to have an opinion).
182
+ # This works only with "--tab".
183
+ attr_accessor :lossless_floats # FALSE
184
+
185
+ #
186
+ # short form: -p; type: string
187
+ # Password to use when connecting.
188
+ attr_accessor :password # (No # value)
189
+
190
+ #
191
+ # type: string
192
+ # Create the given PID file. The file contains the process ID of the script. The PID file is removed
193
+ # when the script exits. Before starting, the script checks if the PID file already exists. If it does
194
+ # not, then the script creates and writes its own PID to it. If it does, then the script checks the
195
+ # following: if the file contains a PID and a process is running with that PID, then the script dies; or,
196
+ # if there is no process running with that PID, then the script overwrites the file with its own PID and
197
+ # starts; else, if the file contains no PID, then the script dies.
198
+ attr_accessor :pid # (No # value)
199
+
200
+ #
201
+ # short form: -P; type: int
202
+ # Port number to use for connection.
203
+ attr_accessor :port # (No # value)
204
+
205
+ #
206
+ # Display progress reports.
207
+ # Progress is displayed each time a table or chunk of a table finishes dumping. Progress is calculated
208
+ # by measuring the average data size of each full chunk and assuming all bytes are created equal. The
209
+ # output is the completed and total bytes, the percent completed, estimated time remaining, and estimated
210
+ # completion time. For example:
211
+ # 40.72k/112.00k 36.36% ETA 00:00 (2009-10-27T19:17:53)
212
+ # If "--chunk-size" is not specified then each table is effectively one big chunk and the progress
213
+ # reports are pretty accurate. When "--chunk-size" is specified the progress reports can be skewed
214
+ # because of averaging.
215
+ # Progress reports are inaccurate when a dump is resumed. This is known issue and will be fixed in a
216
+ # later release.
217
+ attr_accessor :progress # FALSE
218
+
219
+ #
220
+ # short form: -q
221
+ # Quiet output; disables "--verbose".
222
+ attr_accessor :quiet # FALSE
223
+
224
+ #
225
+ # default: yes
226
+ # Resume dumps.
227
+ attr_accessor :resume # TRUE
228
+
229
+ #
230
+ # type: string; default: wait_timeout=10000
231
+ # Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET
232
+ # and executed.
233
+ attr_accessor :set_vars # wait_timeout=10000
234
+
235
+ #
236
+ # short form: -S; type: string
237
+ # Socket file to use for connection.
238
+ attr_accessor :socket # (No # value)
239
+
240
+ #
241
+ # Issue "STOP SLAVE" on server before dumping data.
242
+ # This ensures that the data is not changing during the dump. Issues "START SLAVE" after the dump is
243
+ # complete.
244
+ # If the slave is not running, throws an error and exits. This is to prevent possibly bad things from
245
+ # happening if the slave is not running because of a problem, or because someone intentionally stopped
246
+ # the slave for maintenance or some other purpose.
247
+ attr_accessor :stop_slave # FALSE
248
+
249
+ #
250
+ # Dump tab-separated (sets "--umask" 0).
251
+ # Dump via "SELECT INTO OUTFILE", which is similar to what "mysqldump" does with the "--tab" option, but
252
+ # you're not constrained to a single database at a time.
253
+ # Before you use this option, make sure you know what "SELECT INTO OUTFILE" does! I recommend using it
254
+ # only if you're running mk-parallel-dump on the same machine as the MySQL server, but there is no
255
+ # protection if you don't.
256
+ # This option sets "--umask" to zero so auto-created directories are writable by the MySQL server.
257
+ attr_accessor :tab # FALSE
258
+
259
+ #
260
+ # short form: -t; type: hash
261
+ # Dump only this comma-separated list of table names.
262
+ # Table names may be qualified with the database name.
263
+ attr_accessor :tables # (No # value)
264
+
265
+ #
266
+ # type: string
267
+ # Dump only tables whose names match this Perl regex.
268
+ attr_accessor :tables_regex # (No # value)
269
+
270
+ #
271
+ # type: int; default: 2
272
+ # Number of threads to dump concurrently.
273
+ # Specifies the number of parallel processes to run. The default is 2 (this is mk-parallel-dump, after
274
+ # all -- 1 is not parallel). On GNU/Linux machines, the default is the number of times 'processor'
275
+ # appears in /proc/cpuinfo. On Windows, the default is read from the environment. In any case, the
276
+ # default is at least 2, even when there's only a single processor.
277
+ attr_accessor :threads # 2
278
+
279
+ #
280
+ # default: yes
281
+ # Enable TIMESTAMP columns to be dumped and reloaded between different time zones. mk-parallel-dump sets
282
+ # its connection time zone to UTC and adds "SET TIME_ZONE='+00:00'" to the dump file. Without this
283
+ # option, TIMESTAMP columns are dumped and reloaded in the time zones local to the source and destination
284
+ # servers, which can cause the values to change. This option also protects against changes due to
285
+ # daylight saving time.
286
+ # This option is identical to "mysqldump --tz-utc". In fact, the above text was copied from mysqldump's
287
+ # man page.
288
+ attr_accessor :tz_utc # TRUE
289
+
290
+ #
291
+ # type: string
292
+ # Set the program's "umask" to this octal value.
293
+ # This is useful when you want created files and directories to be readable or writable by other users
294
+ # (for example, the MySQL server itself).
295
+ attr_accessor :umask # (No # value)
296
+
297
+ #
298
+ # short form: -u; type: string
299
+ # User for login if not current user.
300
+ attr_accessor :user # (No # value)
301
+
302
+ #
303
+ # short form: -v; cumulative: yes
304
+ # Be verbose; can specify multiple times.
305
+ # See "OUTPUT".
306
+ attr_accessor :verbose # 0
307
+
308
+ #
309
+ # Show version and exit.
310
+ attr_accessor :version # FALSE
311
+
312
+ #
313
+ # short form: -w; type: time; default: 5m
314
+ # Wait limit when the server is down.
315
+ # If the MySQL server crashes during dumping, waits until the server comes back and then continues with
316
+ # the rest of the tables. "mk-parallel-dump" will check the server every second until this time is
317
+ # exhausted, at which point it will give up and exit.
318
+ # This implements Peter Zaitsev's "safe dump" request: sometimes a dump on a server that has corrupt data
319
+ # will kill the server. mk-parallel-dump will wait for the server to restart, then keep going. It's
320
+ # hard to say which table killed the server, so no tables will be retried. Tables that were being
321
+ # concurrently dumped when the crash happened will not be retried. No additional locks will be taken
322
+ # after the server restarts; it's assumed this behavior is useful only on a server you're not trying to
323
+ # dump while it's in production.
324
+ attr_accessor :wait # 300
325
+
326
+ #
327
+ # default: yes
328
+ # Add a chunk for rows with zero or zero-equivalent values. The only has an effect when "--chunk-size"
329
+ # is specified. The purpose of the zero chunk is to capture a potentially large number of zero values
330
+ # that would imbalance the size of the first chunk. For example, if a lot of negative numbers were
331
+ # inserted into an unsigned integer column causing them to be stored as zeros, then these zero values are
332
+ # captured by the zero chunk instead of the first chunk and all its non-zero values.
333
+ attr_accessor :zero_chunk # TRUE
334
+
335
+ #
336
+ # Sets the executable path, otherwise the environment path will be used.
337
+ #
338
+ attr_accessor :path_to_mk_parallel_dump
339
+
340
+ #
341
+ # Returns a new ParallelDump Object
342
+ #
343
+ def initialize()
344
+ end
345
+
346
+ #
347
+ # Execute the command
348
+ #
349
+ def start(options = nil)
350
+ tmp = Tempfile.new('tmp')
351
+ command = option_string() + options.to_s + " 2> " + tmp.path
352
+ success = system(command)
353
+ if success
354
+ begin
355
+ while (line = tmp.readline)
356
+ line.chomp
357
+ selected_string = line
358
+ end
359
+ rescue EOFError
360
+ tmp.close
361
+ end
362
+ return selected_string
363
+ else
364
+ tmp.close!
365
+ return success
366
+ end
367
+ end
368
+
369
+ def config
370
+ option_string()
371
+ end
372
+
373
+ private
374
+
375
+ def option_string()
376
+
377
+ unless @path_to_mk_parallel_dump
378
+ ostring = "mk-parallel-dump "
379
+ else
380
+ ostring = @path_to_mk_parallel_dump + " "
381
+ end
382
+
383
+ self.instance_variables.each do |i|
384
+ tmp_value = self.instance_variable_get "#{i}"
385
+ tmp_string = i.gsub("_", "-").gsub("@", "--")
386
+ unless tmp_string == "--path-to-mk-parallel-dump"
387
+ if (tmp_value.is_a? TrueClass) || (tmp_value.is_a? FalseClass)
388
+ ostring += "#{tmp_string} "
389
+ else
390
+ ostring += "#{tmp_string} #{tmp_value} "
391
+ end
392
+ end
393
+ end
394
+
395
+ return ostring
396
+
397
+ end
398
+
399
+ end
400
+