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 | * |
||
90 | * Lock tables option |
||
91 | * --lock-tables |
||
92 | * |
||
93 | * @var bool |
||
94 | */ |
||
95 | private $lockTables; |
||
96 | |||
97 | /** |
||
98 | * Use mysqldump with compression |
||
99 | * -C |
||
100 | * |
||
101 | * @var bool |
||
102 | */ |
||
103 | private $compress = false; |
||
104 | |||
105 | /** |
||
106 | * Dump only table structures |
||
107 | * --no-data |
||
108 | * |
||
109 | * @var boolean |
||
110 | */ |
||
111 | private $noData = false; |
||
112 | |||
113 | /** |
||
114 | * Table separated data files |
||
115 | * --tab |
||
116 | * |
||
117 | * @var bool |
||
118 | */ |
||
119 | private $filePerTable; |
||
120 | |||
121 | /** |
||
122 | * Use mysqldump extended insert mode |
||
123 | * -e, --extended-insert |
||
124 | * |
||
125 | * @var boolean |
||
126 | */ |
||
127 | 14 | private $extendedInsert = false; |
|
128 | |||
129 | 14 | /** |
|
130 | 14 | * Dump blob fields as hex. |
|
131 | 14 | * --hex-blob |
|
132 | * |
||
133 | * @var boolean |
||
134 | */ |
||
135 | private $hexBlob = false; |
||
136 | |||
137 | /** |
||
138 | * Path to dump file |
||
139 | * |
||
140 | 3 | * @var string |
|
141 | */ |
||
142 | 3 | private $dumpPathname; |
|
143 | 3 | ||
144 | 3 | /** |
|
145 | * Compression command to pipe output to |
||
146 | * |
||
147 | * @var \phpbu\App\Backup\Target\Compression |
||
148 | */ |
||
149 | private $compression; |
||
150 | |||
151 | /** |
||
152 | * Constructor. |
||
153 | 3 | * |
|
154 | * @param string $path |
||
155 | 3 | */ |
|
156 | 3 | public function __construct($path = null) |
|
161 | |||
162 | /** |
||
163 | * Set the mysql credentials. |
||
164 | * |
||
165 | 3 | * @param string $user |
|
166 | * @param string $password |
||
167 | 3 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
168 | 3 | */ |
|
169 | public function credentials($user = null, $password = null) |
||
175 | |||
176 | /** |
||
177 | 3 | * Set the mysql hostname. |
|
178 | * |
||
179 | 3 | * @param string $host |
|
180 | 3 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
181 | */ |
||
182 | public function useHost($host) |
||
187 | |||
188 | /** |
||
189 | 4 | * Use '-q' quick mode. |
|
190 | * |
||
191 | 4 | * @param boolean $bool |
|
192 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
193 | */ |
||
194 | public function useQuickMode($bool) |
||
199 | |||
200 | /** |
||
201 | 4 | * Use '--lock-tables' option. |
|
202 | * |
||
203 | 4 | * @param boolean $bool |
|
204 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
205 | */ |
||
206 | public function lockTables($bool) |
||
211 | |||
212 | /** |
||
213 | 4 | * Use '-C' compress mode. |
|
214 | * |
||
215 | 4 | * @param boolean $bool |
|
216 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
217 | */ |
||
218 | public function useCompression($bool) |
||
223 | |||
224 | /** |
||
225 | 4 | * Use '-e' extended insert mode. |
|
226 | * |
||
227 | 4 | * @param boolean $bool |
|
228 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
229 | */ |
||
230 | public function useExtendedInsert($bool) |
||
235 | |||
236 | /** |
||
237 | 4 | * Use '--hex-blob' to encode binary fields. |
|
238 | * |
||
239 | 4 | * @param boolean $bool |
|
240 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
241 | */ |
||
242 | public function dumpBlobsHexadecimal($bool) |
||
247 | |||
248 | /** |
||
249 | 4 | * Set tables to dump. |
|
250 | * |
||
251 | 4 | * @param array $tables |
|
252 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
253 | */ |
||
254 | public function dumpTables(array $tables) |
||
259 | |||
260 | /** |
||
261 | 4 | * Set databases to dump. |
|
262 | * |
||
263 | 4 | * @param array $databases |
|
264 | 4 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
265 | */ |
||
266 | public function dumpDatabases(array $databases) |
||
271 | |||
272 | /** |
||
273 | 3 | * Set tables to ignore. |
|
274 | * |
||
275 | 3 | * @param array $tables |
|
276 | 3 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
277 | */ |
||
278 | public function ignoreTables(array $tables) |
||
283 | |||
284 | 11 | /** |
|
285 | 11 | * Set tables where only table structure should be dumped. |
|
286 | 11 | * |
|
287 | * @param array $tables |
||
288 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
289 | 11 | */ |
|
290 | 11 | public function dumpStructureOnly(array $tables) |
|
295 | 11 | ||
296 | 11 | /** |
|
297 | 11 | * Dump no table data at all. |
|
298 | 11 | * |
|
299 | 11 | * @param boolean $bool |
|
300 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
301 | 11 | */ |
|
302 | 1 | public function dumpNoData($bool) |
|
307 | 9 | ||
308 | /** |
||
309 | * Produce table separated data files. |
||
310 | * |
||
311 | 11 | * @param bool $bool |
|
312 | 1 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
313 | 1 | */ |
|
314 | 1 | public function produceFilePerTable($bool) |
|
319 | 10 | ||
320 | 1 | /** |
|
321 | 1 | * Pipe compressor. |
|
322 | 1 | * |
|
323 | 1 | * @param \phpbu\App\Backup\Target\Compression $compression |
|
324 | 1 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
325 | 1 | */ |
|
326 | 1 | public function compressOutput(Compression $compression) |
|
331 | 11 | ||
332 | 11 | /** |
|
333 | * Set the dump target path. |
||
334 | * |
||
335 | * @param string $path |
||
336 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
337 | */ |
||
338 | public function dumpTo($path) |
||
343 | |||
344 | /** |
||
345 | * Process generator |
||
346 | */ |
||
347 | protected function createProcess() |
||
388 | |||
389 | /** |
||
390 | * Configure source data (tables, databases). |
||
391 | * |
||
392 | * @param \phpbu\App\Cli\Cmd $cmd |
||
393 | * @throws \phpbu\App\Exception |
||
394 | */ |
||
395 | private function configureSourceData(Cmd $cmd) |
||
403 | |||
404 | /** |
||
405 | * Configure source tables. |
||
406 | * |
||
407 | * @param \phpbu\App\Cli\Cmd $cmd |
||
408 | * @throws \phpbu\App\Exception |
||
409 | */ |
||
410 | private function configureSourceTables(Cmd $cmd) |
||
418 | |||
419 | /** |
||
420 | * Configure source databases. |
||
421 | * |
||
422 | * @param \phpbu\App\Cli\Cmd $cmd |
||
423 | */ |
||
424 | private function configureSourceDatabases(Cmd $cmd) |
||
440 | |||
441 | /** |
||
442 | * Add --ignore-table options |
||
443 | * |
||
444 | * @param \phpbu\App\Cli\Cmd $cmd |
||
445 | */ |
||
446 | private function configureIgnoredTables(Cmd $cmd) |
||
454 | |||
455 | /** |
||
456 | * Add compressor pipe if set. |
||
457 | * |
||
458 | * @param \phpbu\App\Cli\Process $process |
||
459 | */ |
||
460 | private function configureCompression(Process $process) |
||
469 | |||
470 | /** |
||
471 | * Configure output redirect. |
||
472 | * |
||
473 | * @param \phpbu\App\Cli\Process $process |
||
474 | */ |
||
475 | private function configureOutput(Process $process) |
||
484 | } |
||
485 |