1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Backup; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Cli\Executable; |
5
|
|
|
use phpbu\App\Exception; |
6
|
|
|
use phpbu\App\Util; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Rsync trait. |
10
|
|
|
* |
11
|
|
|
* @package phpbu |
12
|
|
|
* @subpackage Backup |
13
|
|
|
* @author Sebastian Feldmann <[email protected]> |
14
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
15
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
16
|
|
|
* @link http://phpbu.de/ |
17
|
|
|
* @since Class available since Release 3.1.4 |
18
|
|
|
*/ |
19
|
|
|
trait Rsync |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Path to executable. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $pathToRsync; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Raw args |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $args; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Remote username |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $user; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Target host |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $host; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Target path |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $path; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Files to ignore, extracted from config string separated by ":" |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
protected $excludes; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Should only the created backup be synced or the complete directory |
65
|
|
|
* |
66
|
|
|
* @var boolean |
67
|
|
|
*/ |
68
|
|
|
protected $isDirSync; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Remove deleted files. |
72
|
|
|
* |
73
|
|
|
* @var bool |
74
|
|
|
*/ |
75
|
|
|
protected $delete; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Setup the rsync. |
79
|
|
|
* |
80
|
|
|
* @param array $conf |
81
|
|
|
* @throws \phpbu\App\Exception |
82
|
|
|
*/ |
83
|
|
|
protected function setupRsync(array $conf) |
84
|
|
|
{ |
85
|
|
|
$this->pathToRsync = Util\Arr::getValue($conf, 'pathToRsync'); |
86
|
|
|
|
87
|
|
|
if (Util\Arr::isSetAndNotEmptyString($conf, 'args')) { |
88
|
|
|
$this->args = $conf['args']; |
89
|
|
|
} else { |
90
|
|
|
if (!Util\Arr::isSetAndNotEmptyString($conf, 'path')) { |
91
|
|
|
throw new Exception('option \'path\' is missing'); |
92
|
|
|
} |
93
|
|
|
$this->path = Util\Str::replaceDatePlaceholders($conf['path']); |
94
|
|
|
$this->user = Util\Arr::getValue($conf, 'user'); |
95
|
|
|
$this->host = Util\Arr::getValue($conf, 'host'); |
96
|
|
|
$this->excludes = Util\Str::toList(Util\Arr::getValue($conf, 'exclude', ''), ':'); |
97
|
|
|
$this->delete = Util\Str::toBoolean(Util\Arr::getValue($conf, 'delete', ''), false); |
98
|
|
|
$this->isDirSync = Util\Str::toBoolean(Util\Arr::getValue($conf, 'dirsync', ''), false); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return rsync location. |
104
|
|
|
* |
105
|
|
|
* @param \phpbu\App\Backup\Target |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
protected function getRsyncLocation(Target $target) |
109
|
|
|
{ |
110
|
|
|
return $this->isDirSync ? $target->getPath() : $target->getPathname(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|