1 | <?php |
||
22 | class Mysqldump extends Abstraction implements Executable |
||
23 | { |
||
24 | use OptionMasker; |
||
25 | |||
26 | /** |
||
27 | * Host to connect to |
||
28 | * --host <hostname> |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $host; |
||
33 | |||
34 | /** |
||
35 | * User to connect with |
||
36 | * --user <username> |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $user; |
||
41 | |||
42 | /** |
||
43 | * Password to authenticate with |
||
44 | * --password <password> |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $password; |
||
49 | |||
50 | /** |
||
51 | * List of tables to backup |
||
52 | * --tables array of strings |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | private $tablesToDump = []; |
||
57 | |||
58 | /** |
||
59 | * List of databases to backup |
||
60 | * --databases array of strings |
||
61 | * |
||
62 | * @var array |
||
63 | */ |
||
64 | private $databasesToDump = []; |
||
65 | |||
66 | /** |
||
67 | * List of tables to ignore |
||
68 | * |
||
69 | * @var array |
||
70 | */ |
||
71 | private $tablesToIgnore = []; |
||
72 | |||
73 | /** |
||
74 | * List of tables where only the table structure is stored |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | private $structureOnly = []; |
||
79 | |||
80 | /** |
||
81 | * Use mysqldump quick mode |
||
82 | * -q |
||
83 | * |
||
84 | * @var bool |
||
85 | */ |
||
86 | private $quick = false; |
||
87 | |||
88 | /** |
||
89 | * Lock tables option |
||
90 | * --lock-tables |
||
91 | * |
||
92 | * @var bool |
||
93 | */ |
||
94 | private $lockTables; |
||
95 | |||
96 | /** |
||
97 | * Issue a BEGIN SQL statement before dumping data from server |
||
98 | * --single-transaction |
||
99 | * |
||
100 | * @var bool |
||
101 | */ |
||
102 | private $singleTransaction; |
||
103 | |||
104 | /** |
||
105 | * Use mysqldump with compression |
||
106 | * -C |
||
107 | * |
||
108 | * @var bool |
||
109 | */ |
||
110 | private $compress = false; |
||
111 | |||
112 | /** |
||
113 | * Dump only table structures |
||
114 | * --no-data |
||
115 | * |
||
116 | * @var boolean |
||
117 | */ |
||
118 | private $noData = false; |
||
119 | |||
120 | /** |
||
121 | * Table separated data files |
||
122 | * --tab |
||
123 | * |
||
124 | * @var bool |
||
125 | */ |
||
126 | private $filePerTable; |
||
127 | 14 | ||
128 | /** |
||
129 | 14 | * Use mysqldump extended insert mode |
|
130 | 14 | * -e, --extended-insert |
|
131 | 14 | * |
|
132 | * @var boolean |
||
133 | */ |
||
134 | private $extendedInsert = false; |
||
135 | |||
136 | /** |
||
137 | * Dump blob fields as hex. |
||
138 | * --hex-blob |
||
139 | * |
||
140 | 3 | * @var boolean |
|
141 | */ |
||
142 | 3 | private $hexBlob = false; |
|
143 | 3 | ||
144 | 3 | /** |
|
145 | * Path to dump file |
||
146 | * |
||
147 | * @var string |
||
148 | */ |
||
149 | private $dumpPathname; |
||
150 | |||
151 | /** |
||
152 | * Compression command to pipe output to |
||
153 | 3 | * |
|
154 | * @var \phpbu\App\Backup\Target\Compression |
||
155 | 3 | */ |
|
156 | 3 | private $compression; |
|
157 | |||
158 | /** |
||
159 | * Constructor. |
||
160 | * |
||
161 | * @param string $path |
||
162 | */ |
||
163 | public function __construct($path = null) |
||
168 | 3 | ||
169 | /** |
||
170 | * Set the mysql credentials. |
||
171 | * |
||
172 | * @param string $user |
||
173 | * @param string $password |
||
174 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
175 | */ |
||
176 | public function credentials($user = null, $password = null) |
||
182 | |||
183 | /** |
||
184 | * Set the mysql hostname. |
||
185 | * |
||
186 | * @param string $host |
||
187 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
188 | */ |
||
189 | 4 | public function useHost($host) |
|
194 | |||
195 | /** |
||
196 | * Use '-q' quick mode. |
||
197 | * |
||
198 | * @param boolean $bool |
||
199 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
200 | */ |
||
201 | 4 | public function useQuickMode($bool) |
|
206 | |||
207 | /** |
||
208 | * Use '--lock-tables' option. |
||
209 | * |
||
210 | * @param boolean $bool |
||
211 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
212 | */ |
||
213 | 4 | public function lockTables($bool) |
|
218 | |||
219 | /** |
||
220 | * Use '--single-transaction' option. |
||
221 | * |
||
222 | * @param boolean $bool |
||
223 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
224 | */ |
||
225 | 4 | public function singleTransaction($bool) |
|
230 | |||
231 | /** |
||
232 | * Use '-C' compress mode. |
||
233 | * |
||
234 | * @param boolean $bool |
||
235 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
236 | */ |
||
237 | 4 | public function useCompression($bool) |
|
242 | |||
243 | /** |
||
244 | * Use '-e' extended insert mode. |
||
245 | * |
||
246 | * @param boolean $bool |
||
247 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
248 | */ |
||
249 | 4 | public function useExtendedInsert($bool) |
|
254 | |||
255 | /** |
||
256 | * Use '--hex-blob' to encode binary fields. |
||
257 | * |
||
258 | * @param boolean $bool |
||
259 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
260 | */ |
||
261 | 4 | public function dumpBlobsHexadecimal($bool) |
|
266 | |||
267 | /** |
||
268 | * Set tables to dump. |
||
269 | * |
||
270 | * @param array $tables |
||
271 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
272 | */ |
||
273 | 3 | public function dumpTables(array $tables) |
|
278 | |||
279 | /** |
||
280 | * Set databases to dump. |
||
281 | * |
||
282 | 11 | * @param array $databases |
|
283 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
284 | 11 | */ |
|
285 | 11 | public function dumpDatabases(array $databases) |
|
290 | 11 | ||
291 | /** |
||
292 | 11 | * Set tables to ignore. |
|
293 | 11 | * |
|
294 | 11 | * @param array $tables |
|
295 | 11 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
296 | 11 | */ |
|
297 | 11 | public function ignoreTables(array $tables) |
|
302 | 1 | ||
303 | 1 | /** |
|
304 | 10 | * Set tables where only table structure should be dumped. |
|
305 | 1 | * |
|
306 | 1 | * @param array $tables |
|
307 | 9 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
308 | */ |
||
309 | public function dumpStructureOnly(array $tables) |
||
314 | 1 | ||
315 | 1 | /** |
|
316 | 11 | * Dump no table data at all. |
|
317 | 1 | * |
|
318 | 1 | * @param boolean $bool |
|
319 | 10 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
320 | 1 | */ |
|
321 | 1 | public function dumpNoData($bool) |
|
326 | 1 | ||
327 | 1 | /** |
|
328 | 1 | * Produce table separated data files. |
|
329 | 1 | * |
|
330 | * @param bool $bool |
||
331 | 11 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
332 | 11 | */ |
|
333 | public function produceFilePerTable($bool) |
||
338 | |||
339 | /** |
||
340 | * Pipe compressor. |
||
341 | * |
||
342 | * @param \phpbu\App\Backup\Target\Compression $compression |
||
343 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
344 | */ |
||
345 | public function compressOutput(Compression $compression) |
||
350 | |||
351 | /** |
||
352 | * Set the dump target path. |
||
353 | * |
||
354 | * @param string $path |
||
355 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
356 | */ |
||
357 | public function dumpTo($path) |
||
362 | |||
363 | /** |
||
364 | * Process generator |
||
365 | */ |
||
366 | protected function createProcess() |
||
408 | |||
409 | /** |
||
410 | * Configure source data (tables, databases). |
||
411 | * |
||
412 | * @param \phpbu\App\Cli\Cmd $cmd |
||
413 | * @throws \phpbu\App\Exception |
||
414 | */ |
||
415 | private function configureSourceData(Cmd $cmd) |
||
423 | |||
424 | /** |
||
425 | * Configure source tables. |
||
426 | * |
||
427 | * @param \phpbu\App\Cli\Cmd $cmd |
||
428 | * @throws \phpbu\App\Exception |
||
429 | */ |
||
430 | private function configureSourceTables(Cmd $cmd) |
||
438 | |||
439 | /** |
||
440 | * Configure source databases. |
||
441 | * |
||
442 | * @param \phpbu\App\Cli\Cmd $cmd |
||
443 | */ |
||
444 | private function configureSourceDatabases(Cmd $cmd) |
||
460 | |||
461 | /** |
||
462 | * Add --ignore-table options |
||
463 | * |
||
464 | * @param \phpbu\App\Cli\Cmd $cmd |
||
465 | */ |
||
466 | private function configureIgnoredTables(Cmd $cmd) |
||
474 | |||
475 | /** |
||
476 | * Add compressor pipe if set. |
||
477 | * |
||
478 | * @param \phpbu\App\Cli\Process $process |
||
479 | */ |
||
480 | private function configureCompression(Process $process) |
||
489 | |||
490 | /** |
||
491 | * Configure output redirect. |
||
492 | * |
||
493 | * @param \phpbu\App\Cli\Process $process |
||
494 | */ |
||
495 | private function configureOutput(Process $process) |
||
504 | } |
||
505 |