|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App\Backup\Source; |
|
3
|
|
|
|
|
4
|
|
|
use phpbu\App\Backup\Source; |
|
5
|
|
|
use phpbu\App\Backup\Target; |
|
6
|
|
|
use phpbu\App\Cli\Executable; |
|
7
|
|
|
use phpbu\App\Exception; |
|
8
|
|
|
use phpbu\App\Result; |
|
9
|
|
|
use phpbu\App\Util; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Arangodump source class. |
|
13
|
|
|
* |
|
14
|
|
|
* @package phpbu |
|
15
|
|
|
* @subpackage Backup |
|
16
|
|
|
* @author Francis Chuang <[email protected]> |
|
17
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
18
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
|
19
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
20
|
|
|
* @link http://phpbu.de/ |
|
21
|
|
|
* @since Class available since Release 2.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Arangodump extends SimulatorExecutable implements Simulator |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Path to arangodump command. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $pathToArangodump; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Endpoint to connect to |
|
34
|
|
|
* --server.endpoint <endpoint> |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
private $endpoint; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Username to connect with |
|
42
|
|
|
* --server.username <username> |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
private $username; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Password to authenticate with |
|
50
|
|
|
* --server.password <password> |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
private $password; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* The database to backup |
|
58
|
|
|
* --server.database <database> |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $database; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Whether the data should be dumped or not |
|
66
|
|
|
* --dump-data |
|
67
|
|
|
* |
|
68
|
|
|
* @var boolean |
|
69
|
|
|
*/ |
|
70
|
|
|
private $dumpData; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Include system collections |
|
74
|
|
|
* --include-system-collections |
|
75
|
|
|
* |
|
76
|
|
|
* @var boolean |
|
77
|
|
|
*/ |
|
78
|
|
|
private $includeSystemCollections; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Restrict the dump to these collections |
|
82
|
|
|
* --collection |
|
83
|
|
|
* |
|
84
|
|
|
* @var array |
|
85
|
|
|
*/ |
|
86
|
|
|
private $collections; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Do not ask for the username and password when connecting to the server. |
|
90
|
|
|
* This does not control whether the server requires authentication. |
|
91
|
|
|
* -- disable-authentication |
|
92
|
|
|
* |
|
93
|
|
|
* @var boolean |
|
94
|
|
|
*/ |
|
95
|
|
|
private $disableAuthentication; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Setup. |
|
99
|
|
|
* |
|
100
|
|
|
* @see \phpbu\App\Backup\Source |
|
101
|
|
|
* @param array $conf |
|
102
|
|
|
* @throws \phpbu\App\Exception |
|
103
|
|
|
*/ |
|
104
|
|
|
public function setup(array $conf = array()) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->setupSourceData($conf); |
|
107
|
|
|
|
|
108
|
|
|
$this->pathToArangodump = Util\Arr::getValue($conf, 'pathToArangodump'); |
|
109
|
|
|
$this->endpoint = Util\Arr::getValue($conf, 'endpoint'); |
|
110
|
|
|
$this->username = Util\Arr::getValue($conf, 'username'); |
|
111
|
|
|
$this->password = Util\Arr::getValue($conf, 'password'); |
|
112
|
5 |
|
$this->database = Util\Arr::getValue($conf, 'database'); |
|
113
|
|
|
$this->disableAuthentication = Util\Str::toBoolean(Util\Arr::getValue($conf, 'disableAuthentication'), false); |
|
114
|
5 |
|
} |
|
115
|
|
|
|
|
116
|
5 |
|
/** |
|
117
|
5 |
|
* Get collections and data to backup. |
|
118
|
5 |
|
* |
|
119
|
5 |
|
* @param array $conf |
|
120
|
5 |
|
*/ |
|
121
|
5 |
|
protected function setupSourceData(array $conf) |
|
122
|
5 |
|
{ |
|
123
|
5 |
|
$this->dumpData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'dumpData'), false); |
|
124
|
|
|
$this->includeSystemCollections = Util\Str::toBoolean(Util\Arr::getValue($conf, 'includeSystemCollections'), false); |
|
125
|
|
|
$this->collections = Util\Str::toList(Util\Arr::getValue($conf, 'collections')); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* (non-PHPDoc) |
|
130
|
5 |
|
* |
|
131
|
|
|
* @see \phpbu\App\Backup\Source |
|
132
|
5 |
|
* @param \phpbu\App\Backup\Target $target |
|
133
|
5 |
|
* @param \phpbu\App\Result $result |
|
134
|
5 |
|
* @return \phpbu\App\Backup\Source\Status |
|
135
|
5 |
|
* @throws \phpbu\App\Exception |
|
136
|
|
|
*/ |
|
137
|
|
View Code Duplication |
public function backup(Target $target, Result $result) |
|
138
|
|
|
{ |
|
139
|
|
|
$arangodump = $this->execute($target); |
|
140
|
|
|
|
|
141
|
|
|
$result->debug($arangodump->getCmd()); |
|
142
|
|
|
|
|
143
|
|
|
if (!$arangodump->wasSuccessful()) { |
|
144
|
|
|
throw new Exception('arangodump failed: ' . $arangodump->getStdErr()); |
|
145
|
|
|
} |
|
146
|
2 |
|
|
|
147
|
|
|
return $this->createStatus($target); |
|
148
|
2 |
|
} |
|
149
|
|
|
|
|
150
|
2 |
|
/** |
|
151
|
|
|
* Create the Executable to run the arangodump command. |
|
152
|
2 |
|
* |
|
153
|
1 |
|
* @param \phpbu\App\Backup\Target $target |
|
154
|
|
|
* @return \phpbu\App\Cli\Executable |
|
155
|
|
|
* @throws \phpbu\App\Exception |
|
156
|
1 |
|
*/ |
|
157
|
|
View Code Duplication |
public function getExecutable(Target $target) |
|
158
|
|
|
{ |
|
159
|
|
|
if (null == $this->executable) { |
|
160
|
|
|
$this->executable = new Executable\Arangodump($this->pathToArangodump); |
|
161
|
|
|
$this->executable->useEndpoint($this->endpoint) |
|
162
|
|
|
->credentials($this->username, $this->password) |
|
163
|
|
|
->dumpDatabase($this->database) |
|
164
|
|
|
->dumpCollections($this->collections) |
|
165
|
|
|
->disableAuthentication($this->disableAuthentication) |
|
166
|
5 |
|
->includeSystemCollections($this->includeSystemCollections) |
|
167
|
|
|
->dumpData($this->dumpData) |
|
168
|
5 |
|
->dumpTo($this->getDumpDir($target)); |
|
169
|
3 |
|
} |
|
170
|
3 |
|
|
|
171
|
3 |
|
return $this->executable; |
|
172
|
3 |
|
} |
|
173
|
3 |
|
|
|
174
|
3 |
|
/** |
|
175
|
3 |
|
* Create backup status. |
|
176
|
3 |
|
* |
|
177
|
3 |
|
* @param \phpbu\App\Backup\Target |
|
178
|
3 |
|
* @return \phpbu\App\Backup\Source\Status |
|
179
|
3 |
|
*/ |
|
180
|
|
|
protected function createStatus(Target $target) |
|
181
|
5 |
|
{ |
|
182
|
|
|
return Status::create()->uncompressed($this->getDumpDir($target)); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Get the ArangoDB dump directory. |
|
187
|
|
|
* |
|
188
|
|
|
* @param \phpbu\App\Backup\Target $target |
|
189
|
|
|
* @return string |
|
190
|
4 |
|
*/ |
|
191
|
|
|
public function getDumpDir(Target $target) |
|
192
|
4 |
|
{ |
|
193
|
|
|
return $target->getPath() . '/dump'; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|