|
1
|
|
|
<?php |
|
2
|
|
|
namespace phpbu\App\Backup\Sync; |
|
3
|
|
|
|
|
4
|
|
|
use phpseclib; |
|
5
|
|
|
use phpbu\App\Result; |
|
6
|
|
|
use phpbu\App\Backup\Target; |
|
7
|
|
|
use phpbu\App\Util; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Sftp sync |
|
11
|
|
|
* |
|
12
|
|
|
* @package phpbu |
|
13
|
|
|
* @subpackage Backup |
|
14
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
15
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
|
16
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
17
|
|
|
* @link http://phpbu.de/ |
|
18
|
|
|
* @since Class available since Release 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class Xtp implements Simulator |
|
21
|
|
|
{ |
|
22
|
|
|
use Cleanable; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Host to connect to |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $host; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* User to connect with |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $user; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Password to authenticate user |
|
40
|
|
|
* |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $password; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Remote path where to put the backup |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $remotePath; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Check for loaded libraries or extensions. |
|
54
|
|
|
* |
|
55
|
|
|
* @throws \phpbu\App\Backup\Sync\Exception |
|
56
|
|
|
*/ |
|
57
|
|
|
abstract protected function checkRequirements(); |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Return implemented (*)TP protocol name. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
|
|
abstract protected function getProtocolName(); |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* (non-PHPDoc) |
|
68
|
|
|
* |
|
69
|
|
|
* @see \phpbu\App\Backup\Sync::setup() |
|
70
|
|
|
* @param array $config |
|
71
|
|
|
* @throws \phpbu\App\Backup\Sync\Exception |
|
72
|
|
|
*/ |
|
73
|
14 |
|
public function setup(array $config) |
|
74
|
|
|
{ |
|
75
|
14 |
|
$this->checkRequirements(); |
|
76
|
14 |
|
if (!Util\Arr::isSetAndNotEmptyString($config, 'host')) { |
|
77
|
1 |
|
throw new Exception('option \'host\' is missing'); |
|
78
|
|
|
} |
|
79
|
13 |
|
if (!Util\Arr::isSetAndNotEmptyString($config, 'user')) { |
|
80
|
1 |
|
throw new Exception('option \'user\' is missing'); |
|
81
|
|
|
} |
|
82
|
12 |
|
$path = Util\Arr::getValue($config, 'path', ''); |
|
83
|
12 |
|
$this->host = $config['host']; |
|
84
|
12 |
|
$this->user = $config['user']; |
|
85
|
12 |
|
$this->password = Util\Arr::getValue($config, 'password', ''); |
|
86
|
12 |
|
$this->remotePath = Util\Path::withoutTrailingSlash(Util\Path::replaceDatePlaceholders($path)); |
|
87
|
12 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Simulate the sync execution |
|
91
|
|
|
* |
|
92
|
|
|
* @param \phpbu\App\Backup\Target $target |
|
93
|
|
|
* @param \phpbu\App\Result $result |
|
94
|
|
|
*/ |
|
95
|
2 |
|
public function simulate(Target $target, Result $result) |
|
96
|
|
|
{ |
|
97
|
2 |
|
$result->debug( |
|
98
|
2 |
|
'sync backup to ' . $this->getProtocolName() . ' server' . PHP_EOL |
|
99
|
2 |
|
. ' host: ' . $this->host . PHP_EOL |
|
100
|
2 |
|
. ' user: ' . $this->user . PHP_EOL |
|
101
|
2 |
|
. ' password: ********' . PHP_EOL |
|
102
|
2 |
|
. ' path: ' . $this->remotePath . PHP_EOL |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
2 |
|
$this->simulateRemoteCleanup($target, $result); |
|
106
|
2 |
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|