|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App\Configuration; |
|
3
|
|
|
|
|
4
|
|
|
use phpbu\App\Exception; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Backup |
|
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 2.0.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
class Backup |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Backup name |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $name; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Stop all other backups on failure |
|
28
|
|
|
* |
|
29
|
|
|
* @var boolean |
|
30
|
|
|
*/ |
|
31
|
|
|
private $stopOnFailure; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Source configuration |
|
35
|
|
|
* |
|
36
|
|
|
* @var \phpbu\App\Configuration\Backup\Source |
|
37
|
|
|
*/ |
|
38
|
|
|
private $source; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Target configuration |
|
42
|
|
|
* |
|
43
|
|
|
* @var \phpbu\App\Configuration\Backup\Target |
|
44
|
|
|
*/ |
|
45
|
|
|
private $target; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* List of configured Checks |
|
49
|
|
|
* |
|
50
|
|
|
* @var array<\phpbu\App\Configuration\Backup\Check> |
|
51
|
|
|
*/ |
|
52
|
|
|
private $checks = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Crypt configuration |
|
56
|
|
|
* |
|
57
|
|
|
* @var \phpbu\App\Configuration\Backup\Crypt |
|
58
|
|
|
*/ |
|
59
|
|
|
private $crypt; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* List of configured Syncs |
|
63
|
|
|
* |
|
64
|
|
|
* @var array<\phpbu\App\Configuration\Backup\Sync> |
|
65
|
|
|
*/ |
|
66
|
|
|
private $syncs = []; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Cleanup configuration |
|
70
|
|
|
* |
|
71
|
|
|
* @var \phpbu\App\Configuration\Backup\Cleanup |
|
72
|
|
|
*/ |
|
73
|
|
|
private $cleanup; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Constructor |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* @param boolean $stopOnFailure |
|
80
|
|
|
*/ |
|
81
|
30 |
|
public function __construct($name, $stopOnFailure) |
|
82
|
|
|
{ |
|
83
|
30 |
|
$this->name = $name; |
|
84
|
30 |
|
$this->stopOnFailure = $stopOnFailure; |
|
85
|
30 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Returns name for the backup. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string |
|
91
|
|
|
* @throws \phpbu\App\Exception |
|
92
|
|
|
*/ |
|
93
|
12 |
|
public function getName() |
|
94
|
|
|
{ |
|
95
|
12 |
|
if (!empty($this->name)) { |
|
96
|
10 |
|
return $this->name; |
|
97
|
|
|
} |
|
98
|
2 |
|
if (!empty($this->source)) { |
|
99
|
1 |
|
return $this->source->type; |
|
100
|
|
|
} |
|
101
|
1 |
|
throw new Exception('no name and no source'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* StopOnFailure getter. |
|
106
|
|
|
* |
|
107
|
|
|
* @return boolean |
|
108
|
|
|
*/ |
|
109
|
1 |
|
public function stopOnFailure() |
|
110
|
|
|
{ |
|
111
|
1 |
|
return $this->stopOnFailure; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Data source setter. |
|
116
|
|
|
* |
|
117
|
|
|
* @param \phpbu\App\Configuration\Backup\Source $source |
|
118
|
|
|
*/ |
|
119
|
14 |
|
public function setSource(Backup\Source $source) |
|
120
|
|
|
{ |
|
121
|
14 |
|
$this->source = $source; |
|
122
|
14 |
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Source getter. |
|
126
|
|
|
* |
|
127
|
|
|
* @return \phpbu\App\Configuration\Backup\Source |
|
128
|
|
|
*/ |
|
129
|
3 |
|
public function getSource() |
|
130
|
|
|
{ |
|
131
|
3 |
|
return $this->source; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Target setter. |
|
136
|
|
|
* |
|
137
|
|
|
* @param \phpbu\App\Configuration\Backup\Target $target |
|
138
|
|
|
*/ |
|
139
|
9 |
|
public function setTarget(Backup\Target $target) |
|
140
|
|
|
{ |
|
141
|
9 |
|
$this->target = $target; |
|
142
|
9 |
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Target getter. |
|
146
|
|
|
* |
|
147
|
|
|
* @return \phpbu\App\Configuration\Backup\Target |
|
148
|
|
|
*/ |
|
149
|
1 |
|
public function getTarget() |
|
150
|
|
|
{ |
|
151
|
1 |
|
return $this->target; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Adds a check to the list. |
|
156
|
|
|
* |
|
157
|
|
|
* @param \phpbu\App\Configuration\Backup\Check $check |
|
158
|
|
|
*/ |
|
159
|
9 |
|
public function addCheck(Backup\Check $check) |
|
160
|
|
|
{ |
|
161
|
9 |
|
$this->checks[] = $check; |
|
162
|
9 |
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Returns list of checks. |
|
166
|
|
|
* |
|
167
|
|
|
* @return array<\phpbu\App\Configuration\Backup\Check> |
|
168
|
|
|
*/ |
|
169
|
4 |
|
public function getChecks() |
|
170
|
|
|
{ |
|
171
|
4 |
|
return $this->checks; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Crypt setter. |
|
176
|
|
|
* |
|
177
|
|
|
* @param \phpbu\App\Configuration\Backup\Crypt $crypt |
|
178
|
|
|
*/ |
|
179
|
6 |
|
public function setCrypt(Backup\Crypt $crypt) |
|
180
|
|
|
{ |
|
181
|
6 |
|
$this->crypt = $crypt; |
|
182
|
6 |
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Crypt getter. |
|
186
|
|
|
* |
|
187
|
|
|
* @return \phpbu\App\Configuration\Backup\Crypt |
|
188
|
|
|
*/ |
|
189
|
1 |
|
public function getCrypt() |
|
190
|
|
|
{ |
|
191
|
1 |
|
return $this->crypt; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Is crypt set. |
|
196
|
|
|
* |
|
197
|
|
|
* @return bool |
|
198
|
|
|
*/ |
|
199
|
8 |
|
public function hasCrypt() |
|
200
|
|
|
{ |
|
201
|
8 |
|
return !empty($this->crypt); |
|
202
|
8 |
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Add sync to list. |
|
206
|
|
|
* |
|
207
|
|
|
* @param \phpbu\App\Configuration\Backup\Sync $sync |
|
208
|
|
|
*/ |
|
209
|
3 |
|
public function addSync(Backup\Sync $sync) |
|
210
|
|
|
{ |
|
211
|
3 |
|
$this->syncs[] = $sync; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Returns list of syncs. |
|
216
|
|
|
* |
|
217
|
|
|
* @return array<\phpbu\App\Configuration\Backup\Sync> |
|
218
|
|
|
*/ |
|
219
|
6 |
|
public function getSyncs() |
|
220
|
|
|
{ |
|
221
|
6 |
|
return $this->syncs; |
|
222
|
6 |
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Cleanup setter. |
|
226
|
|
|
* |
|
227
|
|
|
* @param \phpbu\App\Configuration\Backup\Cleanup $cleanup |
|
228
|
|
|
*/ |
|
229
|
1 |
|
public function setCleanup(Backup\Cleanup $cleanup) |
|
230
|
|
|
{ |
|
231
|
1 |
|
$this->cleanup = $cleanup; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Cleanup getter. |
|
236
|
|
|
* |
|
237
|
|
|
* @return \phpbu\App\Configuration\Backup\Cleanup |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getCleanup() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->cleanup; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Is cleanup set. |
|
246
|
|
|
* |
|
247
|
|
|
* @return bool |
|
248
|
|
|
*/ |
|
249
|
|
|
public function hasCleanup() |
|
250
|
|
|
{ |
|
251
|
|
|
return !empty($this->cleanup); |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|