1 | <?php |
||
22 | class Redis extends SimulatorExecutable implements Simulator, Restorable |
||
23 | { |
||
24 | /** |
||
25 | * Executable to handle redis command. |
||
26 | * |
||
27 | * @var \phpbu\App\Cli\Executable\RedisCli |
||
28 | */ |
||
29 | protected $executable; |
||
30 | |||
31 | /** |
||
32 | * Path to executable. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $pathToRedisCli; |
||
37 | |||
38 | /** |
||
39 | * Time to wait for the dump to finish, 45 seconds by default |
||
40 | * |
||
41 | * @var integer |
||
42 | */ |
||
43 | private $timeout; |
||
44 | |||
45 | /** |
||
46 | * Host to backup |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | private $host; |
||
51 | |||
52 | /** |
||
53 | * Port to connect to |
||
54 | * |
||
55 | * @var int |
||
56 | */ |
||
57 | private $port; |
||
58 | |||
59 | /** |
||
60 | * Password for authentication |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | private $password; |
||
65 | |||
66 | /** |
||
67 | * Path to the redis rdb directory, for Debian it's /var/lib/redis/{PORT}/dump.rdb |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | private $pathToRedisData; |
||
72 | |||
73 | /** |
||
74 | * Setup. |
||
75 | * |
||
76 | * @see \phpbu\App\Backup\Source |
||
77 | * @param array $conf |
||
78 | * @throws \phpbu\App\Exception |
||
79 | */ |
||
80 | 7 | public function setup(array $conf = []) |
|
93 | |||
94 | /** |
||
95 | * Execute the backup. |
||
96 | * |
||
97 | * @see \phpbu\App\Backup\Source |
||
98 | * @param \phpbu\App\Backup\Target $target |
||
99 | * @param \phpbu\App\Result $result |
||
100 | * @return \phpbu\App\Backup\Source\Status |
||
101 | * @throws \phpbu\App\Exception |
||
102 | */ |
||
103 | 5 | public function backup(Target $target, Result $result) : Status |
|
123 | |||
124 | /** |
||
125 | * Setup the Executable to run the 'tar' command. |
||
126 | * |
||
127 | * @param \phpbu\App\Backup\Target $target |
||
128 | * @return \phpbu\App\Cli\Executable |
||
129 | */ |
||
130 | 6 | protected function createExecutable(Target $target) : Executable |
|
139 | |||
140 | /** |
||
141 | * Creates a RedisLastSave command from a RedisSave command. |
||
142 | * |
||
143 | * @param \phpbu\App\Cli\Executable\RedisCli $redis |
||
144 | * @return \phpbu\App\Cli\Executable\RedisCli |
||
145 | */ |
||
146 | 5 | public function getRedisLastSave(Executable\RedisCli $redis) : Executable\RedisCli |
|
152 | |||
153 | /** |
||
154 | * Return last successful save timestamp. |
||
155 | * |
||
156 | * @param \phpbu\App\Cli\Executable\RedisCli $redis |
||
157 | * @return int |
||
158 | * @throws \phpbu\App\Exception |
||
159 | */ |
||
160 | 5 | private function getLastBackupTime(Executable\RedisCli $redis) : int |
|
170 | |||
171 | /** |
||
172 | * Check the dump date and return true if BGSAVE is finished. |
||
173 | * |
||
174 | * @param int $lastTimestamp |
||
175 | * @param \phpbu\App\Cli\Executable\RedisCli $redis |
||
176 | * @return bool |
||
177 | * @throws \phpbu\App\Exception |
||
178 | */ |
||
179 | 3 | private function isDumpCreatedYet($lastTimestamp, $redis) : bool |
|
191 | |||
192 | /** |
||
193 | * Copy the redis RDB file to its backup location. |
||
194 | * |
||
195 | * @param \phpbu\App\Backup\Target $target |
||
196 | * @return string |
||
197 | * @throws \phpbu\App\Exception |
||
198 | */ |
||
199 | 2 | private function copyDumpToTarget(Target $target) : string |
|
208 | |||
209 | /** |
||
210 | * Create backup status. |
||
211 | * |
||
212 | * @param \phpbu\App\Backup\Target $target |
||
213 | * @return \phpbu\App\Backup\Source\Status |
||
214 | */ |
||
215 | 1 | protected function createStatus(Target $target) : Status |
|
219 | |||
220 | /** |
||
221 | * Restore the backup |
||
222 | * |
||
223 | * @param \phpbu\App\Backup\Target $target |
||
224 | * @param \phpbu\App\Backup\Restore\Plan $plan |
||
225 | * @return \phpbu\App\Backup\Source\Status |
||
226 | */ |
||
227 | public function restore(Target $target, Plan $plan): Status |
||
239 | } |
||
240 |