1 | <?php |
||
20 | class Mysqldump extends Abstraction implements Executable |
||
21 | { |
||
22 | use OptionMasker; |
||
23 | |||
24 | /** |
||
25 | * Host to connect to |
||
26 | * --host <hostname> |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $host; |
||
31 | |||
32 | /** |
||
33 | * User to connect with |
||
34 | * --user <username> |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $user; |
||
39 | |||
40 | /** |
||
41 | * Password to authenticate with |
||
42 | * --password <password> |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $password; |
||
47 | |||
48 | /** |
||
49 | * List of tables to backup |
||
50 | * --tables array of strings |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | private $tablesToDump = []; |
||
55 | |||
56 | /** |
||
57 | * List of databases to backup |
||
58 | * --databases array of strings |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | private $databasesToDump = []; |
||
63 | |||
64 | /** |
||
65 | * List of tables to ignore |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | private $tablesToIgnore = []; |
||
70 | |||
71 | /** |
||
72 | * List of tables where only the table structure is stored |
||
73 | * |
||
74 | * @var array |
||
75 | */ |
||
76 | private $structureOnly = []; |
||
77 | |||
78 | /** |
||
79 | * Use mysqldump quick mode |
||
80 | * -q |
||
81 | * |
||
82 | * @var bool |
||
83 | */ |
||
84 | private $quick = false; |
||
85 | |||
86 | /** |
||
87 | * |
||
88 | * Lock tables option |
||
89 | * --lock-tables |
||
90 | * |
||
91 | * @var bool |
||
92 | */ |
||
93 | private $lockTables; |
||
94 | |||
95 | /** |
||
96 | * Use mysqldump with compression |
||
97 | * -C |
||
98 | * |
||
99 | * @var bool |
||
100 | */ |
||
101 | private $compress = false; |
||
102 | |||
103 | /** |
||
104 | * Dump only table structures |
||
105 | * --no-data |
||
106 | * |
||
107 | * @var boolean |
||
108 | */ |
||
109 | private $noData = false; |
||
110 | |||
111 | /** |
||
112 | * Table separated data files |
||
113 | * --tab |
||
114 | * |
||
115 | * @var bool |
||
116 | */ |
||
117 | private $filePerTable; |
||
118 | |||
119 | /** |
||
120 | * Use mysqldump extended insert mode |
||
121 | * -e, --extended-insert |
||
122 | * |
||
123 | * @var boolean |
||
124 | */ |
||
125 | private $extendedInsert = false; |
||
126 | |||
127 | 14 | /** |
|
128 | * Dump blob fields as hex. |
||
129 | 14 | * --hex-blob |
|
130 | 14 | * |
|
131 | 14 | * @var boolean |
|
132 | */ |
||
133 | private $hexBlob = false; |
||
134 | |||
135 | /** |
||
136 | * Path to dump file |
||
137 | * |
||
138 | * @var string |
||
139 | */ |
||
140 | 3 | private $dumpPathname; |
|
141 | |||
142 | 3 | /** |
|
143 | 3 | * Constructor. |
|
144 | 3 | * |
|
145 | * @param string $path |
||
146 | */ |
||
147 | public function __construct($path = null) |
||
152 | |||
153 | 3 | /** |
|
154 | * Set the mysql credentials. |
||
155 | 3 | * |
|
156 | 3 | * @param string $user |
|
157 | * @param string $password |
||
158 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
159 | */ |
||
160 | public function credentials($user = null, $password = null) |
||
166 | |||
167 | 3 | /** |
|
168 | 3 | * Set the mysql hostname. |
|
169 | * |
||
170 | * @param string $host |
||
171 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
172 | */ |
||
173 | public function useHost($host) |
||
178 | |||
179 | 3 | /** |
|
180 | 3 | * Use '-q' quick mode. |
|
181 | * |
||
182 | * @param boolean $bool |
||
183 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
184 | */ |
||
185 | public function useQuickMode($bool) |
||
190 | |||
191 | 4 | /** |
|
192 | 4 | * Use '--lock-tables' option. |
|
193 | * |
||
194 | * @param boolean $bool |
||
195 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
196 | */ |
||
197 | public function lockTables($bool) |
||
202 | |||
203 | 4 | /** |
|
204 | 4 | * Use '-C' compress mode. |
|
205 | * |
||
206 | * @param boolean $bool |
||
207 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
208 | */ |
||
209 | public function useCompression($bool) |
||
214 | |||
215 | 4 | /** |
|
216 | 4 | * Use '-e' extended insert mode. |
|
217 | * |
||
218 | * @param boolean $bool |
||
219 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
220 | */ |
||
221 | public function useExtendedInsert($bool) |
||
226 | |||
227 | 4 | /** |
|
228 | 4 | * Use '--hex-blob' to encode binary fields. |
|
229 | * |
||
230 | * @param boolean $bool |
||
231 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
232 | */ |
||
233 | public function dumpBlobsHexadecimal($bool) |
||
238 | |||
239 | 4 | /** |
|
240 | 4 | * Set tables to dump. |
|
241 | * |
||
242 | * @param array $tables |
||
243 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
244 | */ |
||
245 | public function dumpTables(array $tables) |
||
250 | |||
251 | 4 | /** |
|
252 | 4 | * Set databases to dump. |
|
253 | * |
||
254 | * @param array $databases |
||
255 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
256 | */ |
||
257 | public function dumpDatabases(array $databases) |
||
262 | |||
263 | 4 | /** |
|
264 | 4 | * Set tables to ignore. |
|
265 | * |
||
266 | * @param array $tables |
||
267 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
268 | */ |
||
269 | public function ignoreTables(array $tables) |
||
274 | |||
275 | 3 | /** |
|
276 | 3 | * Set tables where only table structure should be dumped. |
|
277 | * |
||
278 | * @param array $tables |
||
279 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
280 | */ |
||
281 | public function dumpStructureOnly(array $tables) |
||
286 | 11 | ||
287 | /** |
||
288 | * Dump no table data at all. |
||
289 | 11 | * |
|
290 | 11 | * @param boolean $bool |
|
291 | * @return \phpbu\App\Cli\Executable\Mysqldump |
||
292 | 11 | */ |
|
293 | 11 | public function dumpNoData($bool) |
|
298 | 11 | ||
299 | 11 | /** |
|
300 | * Produce table separated data files. |
||
301 | 11 | * |
|
302 | 1 | * @param bool $bool |
|
303 | 1 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
304 | 10 | */ |
|
305 | 1 | public function produceFilePerTable($bool) |
|
310 | |||
311 | 11 | /** |
|
312 | 1 | * Set the dump target path. |
|
313 | 1 | * |
|
314 | 1 | * @param string $path |
|
315 | 1 | * @return \phpbu\App\Cli\Executable\Mysqldump |
|
316 | 11 | */ |
|
317 | 1 | public function dumpTo($path) |
|
322 | 1 | ||
323 | 1 | /** |
|
324 | 1 | * Process generator |
|
325 | 1 | */ |
|
326 | 1 | protected function createProcess() |
|
366 | |||
367 | /** |
||
368 | * Configure source data (tables, databases). |
||
369 | * |
||
370 | * @param \phpbu\App\Cli\Cmd $cmd |
||
371 | * @throws \phpbu\App\Exception |
||
372 | */ |
||
373 | private function configureSourceData(Cmd $cmd) |
||
381 | |||
382 | /** |
||
383 | * Configure source tables. |
||
384 | * |
||
385 | * @param \phpbu\App\Cli\Cmd $cmd |
||
386 | * @throws \phpbu\App\Exception |
||
387 | */ |
||
388 | private function configureSourceTables(Cmd $cmd) |
||
396 | |||
397 | /** |
||
398 | * Configure source databases. |
||
399 | * |
||
400 | * @param \phpbu\App\Cli\Cmd $cmd |
||
401 | */ |
||
402 | private function configureSourceDatabases(Cmd $cmd) |
||
418 | |||
419 | /** |
||
420 | * Add --ignore-table options |
||
421 | * |
||
422 | * @param \phpbu\App\Cli\Cmd $cmd |
||
423 | */ |
||
424 | private function configureIgnoredTables(Cmd $cmd) |
||
432 | |||
433 | /** |
||
434 | * Configure output redirect. |
||
435 | * |
||
436 | * @param \phpbu\App\Cli\Process $process |
||
437 | */ |
||
438 | private function configureOutput(Process $process) |
||
444 | } |
||
445 |