1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Result; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Configuration; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Backup Result |
8
|
|
|
* |
9
|
|
|
* @package phpbu |
10
|
|
|
* @subpackage App |
11
|
|
|
* @author Sebastian Feldmann <[email protected]> |
12
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
13
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
14
|
|
|
* @link http://phpbu.de/ |
15
|
|
|
* @since Class available since Release 1.0.0 |
16
|
|
|
*/ |
17
|
|
|
class Backup |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Backup name |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $name; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Backup was successful |
28
|
|
|
* |
29
|
|
|
* @var boolean |
30
|
|
|
*/ |
31
|
|
|
protected $wasSuccessful = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* List of executed checks |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $checks = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* List of failed checks |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $checksFailed = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* List of executed crypts |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $crypts = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* List of skipped crypts |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
protected $cryptsSkipped = []; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* List of failed crypts |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
protected $cryptsFailed = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* List of executed syncs |
70
|
|
|
* |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
protected $syncs = []; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* List of skipped syncs |
77
|
|
|
* |
78
|
|
|
* @var array |
79
|
|
|
*/ |
80
|
|
|
protected $syncsSkipped = []; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* List of failed syncs |
84
|
|
|
* |
85
|
|
|
* @var array |
86
|
|
|
*/ |
87
|
|
|
protected $syncsFailed = []; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* List of executed cleanups |
91
|
|
|
* |
92
|
|
|
* @var array |
93
|
|
|
*/ |
94
|
|
|
protected $cleanups = []; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* List of skipped cleanups |
98
|
|
|
* |
99
|
|
|
* @var array |
100
|
|
|
*/ |
101
|
|
|
protected $cleanupsSkipped = []; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* List of failed cleanups |
105
|
|
|
* |
106
|
|
|
* @var array |
107
|
|
|
*/ |
108
|
|
|
protected $cleanupsFailed = []; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Constructor |
112
|
|
|
* |
113
|
|
|
* @param string $name |
114
|
|
|
*/ |
115
|
26 |
|
public function __construct($name) |
116
|
|
|
{ |
117
|
26 |
|
$this->name = $name; |
118
|
26 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Type getter |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
1 |
|
public function getName() : string |
126
|
|
|
{ |
127
|
1 |
|
return $this->name; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Backup successful and nothing skipped or failed. |
132
|
|
|
* |
133
|
|
|
* @return bool |
134
|
|
|
*/ |
135
|
1 |
|
public function allOk() : bool |
136
|
|
|
{ |
137
|
1 |
|
return $this->wasSuccessful() && $this->noneSkipped() && $this->noneFailed(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Backup successful but something was skipped or failed. |
142
|
|
|
* |
143
|
|
|
* @return bool |
144
|
|
|
*/ |
145
|
1 |
|
public function okButSkipsOrFails() : bool |
146
|
|
|
{ |
147
|
1 |
|
return $this->wasSuccessful() && (!$this->noneFailed() || !$this->noneSkipped()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Backup executed successfully and no checks failed. |
152
|
|
|
* |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
4 |
|
public function wasSuccessful() : bool |
156
|
|
|
{ |
157
|
4 |
|
return $this->wasSuccessful; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* No skipped crypts, syncs or cleanups. |
162
|
|
|
* |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
1 |
|
public function noneSkipped() : bool |
166
|
|
|
{ |
167
|
1 |
|
return count($this->cryptsFailed) + count($this->syncsSkipped) + count($this->cleanupsSkipped) === 0; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* No failed crypts, syncs or cleanups. |
172
|
|
|
* |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
1 |
|
public function noneFailed() : bool |
176
|
|
|
{ |
177
|
1 |
|
return count($this->cryptsFailed) + count($this->syncsFailed) + count($this->cleanupsFailed) === 0; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Mark backup as failed. |
182
|
|
|
*/ |
183
|
7 |
|
public function fail() |
184
|
|
|
{ |
185
|
7 |
|
$this->wasSuccessful = false; |
186
|
7 |
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Add check to executed list. |
190
|
|
|
* |
191
|
|
|
* @param \phpbu\App\Configuration\Backup\Check $check |
192
|
|
|
*/ |
193
|
17 |
|
public function checkAdd(Configuration\Backup\Check $check) |
194
|
|
|
{ |
195
|
17 |
|
$this->checks[] = $check; |
196
|
17 |
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Return amount of executed checks. |
200
|
|
|
* |
201
|
|
|
* @return int |
202
|
|
|
*/ |
203
|
1 |
|
public function checkCount() : int |
204
|
|
|
{ |
205
|
1 |
|
return count($this->checks); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Add check to failed checks list. |
210
|
|
|
* |
211
|
|
|
* @param \phpbu\App\Configuration\Backup\Check $check |
212
|
|
|
*/ |
213
|
4 |
|
public function checkFailed(Configuration\Backup\Check$check) |
214
|
|
|
{ |
215
|
4 |
|
$this->checksFailed[] = $check; |
216
|
4 |
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Return amount of failed checks. |
220
|
|
|
* |
221
|
|
|
* @return int |
222
|
|
|
*/ |
223
|
1 |
|
public function checkCountFailed() : int |
224
|
|
|
{ |
225
|
1 |
|
return count($this->checksFailed); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Add crypt to executed list. |
230
|
|
|
* |
231
|
|
|
* @param \phpbu\App\Configuration\Backup\Crypt $crypt |
232
|
|
|
*/ |
233
|
15 |
|
public function cryptAdd(Configuration\Backup\Crypt $crypt) |
234
|
|
|
{ |
235
|
15 |
|
$this->crypts[] = $crypt; |
236
|
15 |
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Return amount of executed crypts. |
240
|
|
|
* |
241
|
|
|
* @return int |
242
|
|
|
*/ |
243
|
1 |
|
public function cryptCount() : int |
244
|
|
|
{ |
245
|
1 |
|
return count($this->crypts); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Add crypt to skipped syncs list. |
250
|
|
|
* |
251
|
|
|
* @param \phpbu\App\Configuration\Backup\Crypt $crypt |
252
|
|
|
*/ |
253
|
4 |
|
public function cryptSkipped(Configuration\Backup\Crypt $crypt) |
254
|
|
|
{ |
255
|
4 |
|
$this->cryptsSkipped[] = $crypt; |
256
|
4 |
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Return amount of failed crypts. |
260
|
|
|
* |
261
|
|
|
* @return int |
262
|
|
|
*/ |
263
|
1 |
|
public function cryptCountSkipped() : int |
264
|
|
|
{ |
265
|
1 |
|
return count($this->cryptsSkipped); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Add crypt to failed crypts list. |
270
|
|
|
* |
271
|
|
|
* @param \phpbu\App\Configuration\Backup\Crypt $crypt |
272
|
|
|
*/ |
273
|
3 |
|
public function cryptFailed(Configuration\Backup\Crypt $crypt) |
274
|
|
|
{ |
275
|
3 |
|
$this->cryptsFailed[] = $crypt; |
276
|
3 |
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Return amount of failed crypts. |
280
|
|
|
* |
281
|
|
|
* @return int |
282
|
|
|
*/ |
283
|
1 |
|
public function cryptCountFailed() : int |
284
|
|
|
{ |
285
|
1 |
|
return count($this->cryptsFailed); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Add sync to executed syncs list. |
290
|
|
|
* |
291
|
|
|
* @param \phpbu\App\Configuration\Backup\Sync $sync |
292
|
|
|
*/ |
293
|
10 |
|
public function syncAdd(Configuration\Backup\Sync $sync) |
294
|
|
|
{ |
295
|
10 |
|
$this->syncs[] = $sync; |
296
|
10 |
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Return count of executed syncs. |
300
|
|
|
* |
301
|
|
|
* @return int |
302
|
|
|
*/ |
303
|
1 |
|
public function syncCount() : int |
304
|
|
|
{ |
305
|
1 |
|
return count($this->syncs); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Add sync to skipped syncs list. |
310
|
|
|
* |
311
|
|
|
* @param \phpbu\App\Configuration\Backup\Sync $sync |
312
|
|
|
*/ |
313
|
5 |
|
public function syncSkipped(Configuration\Backup\Sync $sync) |
314
|
|
|
{ |
315
|
5 |
|
$this->syncsSkipped[] = $sync; |
316
|
5 |
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Return amount of skipped syncs. |
320
|
|
|
* |
321
|
|
|
* @return int |
322
|
|
|
*/ |
323
|
1 |
|
public function syncCountSkipped() : int |
324
|
|
|
{ |
325
|
1 |
|
return count($this->syncsSkipped); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Add sync to failed syncs list. |
330
|
|
|
* |
331
|
|
|
* @param \phpbu\App\Configuration\Backup\Sync $sync |
332
|
|
|
*/ |
333
|
3 |
|
public function syncFailed(Configuration\Backup\Sync $sync) |
334
|
|
|
{ |
335
|
3 |
|
$this->syncsFailed[] = $sync; |
336
|
3 |
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Return amount of failed syncs. |
340
|
|
|
* |
341
|
|
|
* @return int |
342
|
|
|
*/ |
343
|
1 |
|
public function syncCountFailed() : int |
344
|
|
|
{ |
345
|
1 |
|
return count($this->syncsFailed); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Add cleanup to executed cleanups list. |
350
|
|
|
* |
351
|
|
|
* @param \phpbu\App\Configuration\Backup\Cleanup $cleanup |
352
|
|
|
*/ |
353
|
15 |
|
public function cleanupAdd(Configuration\Backup\Cleanup $cleanup) |
354
|
|
|
{ |
355
|
15 |
|
$this->cleanups[] = $cleanup; |
356
|
15 |
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Return amount of executed cleanups. |
360
|
|
|
* |
361
|
|
|
* @return int |
362
|
|
|
*/ |
363
|
1 |
|
public function cleanupCount() : int |
364
|
|
|
{ |
365
|
1 |
|
return count($this->cleanups); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Add cleanup to skipped cleanups list. |
370
|
|
|
* |
371
|
|
|
* @param \phpbu\App\Configuration\Backup\Cleanup $cleanup |
372
|
|
|
*/ |
373
|
6 |
|
public function cleanupSkipped(Configuration\Backup\Cleanup $cleanup) |
374
|
|
|
{ |
375
|
6 |
|
$this->cleanupsSkipped[] = $cleanup; |
376
|
6 |
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Return amount of skipped cleanups |
380
|
|
|
* |
381
|
|
|
* @return int |
382
|
|
|
*/ |
383
|
1 |
|
public function cleanupCountSkipped() : int |
384
|
|
|
{ |
385
|
1 |
|
return count($this->cleanupsSkipped); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Add cleanup to failed cleanups list. |
390
|
|
|
* |
391
|
|
|
* @param \phpbu\App\Configuration\Backup\Cleanup $cleanup |
392
|
|
|
*/ |
393
|
3 |
|
public function cleanupFailed(Configuration\Backup\Cleanup $cleanup) |
394
|
|
|
{ |
395
|
3 |
|
$this->cleanupsFailed[] = $cleanup; |
396
|
3 |
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Return amount of failed cleanups. |
400
|
|
|
* |
401
|
|
|
* @return int |
402
|
|
|
*/ |
403
|
1 |
|
public function cleanupCountFailed() : int |
404
|
|
|
{ |
405
|
1 |
|
return count($this->cleanupsFailed); |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|