1 | <?php |
||
21 | class Rsync extends Abstraction implements Executable |
||
22 | { |
||
23 | use OptionMasker; |
||
24 | |||
25 | /** |
||
26 | * Source |
||
27 | * |
||
28 | * @var \phpbu\App\Cli\Executable\Rsync\Location |
||
29 | */ |
||
30 | private $source; |
||
31 | |||
32 | /** |
||
33 | * Target |
||
34 | * |
||
35 | * @var \phpbu\App\Cli\Executable\Rsync\Location |
||
36 | */ |
||
37 | private $target; |
||
38 | |||
39 | /** |
||
40 | * Password to use to authenticate |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | private $password; |
||
45 | |||
46 | /** |
||
47 | * Path to password file |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $passwordFile; |
||
52 | |||
53 | /** |
||
54 | * Raw args |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $args; |
||
59 | |||
60 | /** |
||
61 | * Files to ignore, extracted from config string separated by ":" |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $excludes = []; |
||
66 | |||
67 | /** |
||
68 | * Remove deleted files remotely as well |
||
69 | * |
||
70 | * @var boolean |
||
71 | */ |
||
72 | protected $delete; |
||
73 | |||
74 | /** |
||
75 | * Compress data. |
||
76 | * |
||
77 | * @var boolean |
||
78 | */ |
||
79 | protected $compressed = false; |
||
80 | |||
81 | /** |
||
82 | * Constructor. |
||
83 | 15 | * |
|
84 | * @param string $path |
||
85 | 15 | */ |
|
86 | 15 | public function __construct(string $path = '') |
|
93 | |||
94 | /** |
||
95 | 2 | * Set custom args |
|
96 | * |
||
97 | 2 | * @param string $args |
|
98 | 2 | * @return \phpbu\App\Cli\Executable\Rsync |
|
99 | */ |
||
100 | public function useArgs(string $args) : Rsync |
||
105 | |||
106 | /** |
||
107 | 8 | * Set password environment variable RSYNC_PASSWORD. |
|
108 | * |
||
109 | 8 | * @param string $password |
|
110 | 8 | * @return \phpbu\App\Cli\Executable\Rsync |
|
111 | */ |
||
112 | public function usePassword(string $password) |
||
117 | |||
118 | /** |
||
119 | 4 | * Set path to password file. |
|
120 | * |
||
121 | 4 | * @param string $file |
|
122 | 4 | * @return \phpbu\App\Cli\Executable\Rsync |
|
123 | */ |
||
124 | public function usePasswordFile(string $file) |
||
129 | |||
130 | |||
131 | 5 | /** |
|
132 | * Set source user. |
||
133 | 5 | * |
|
134 | 5 | * @param string $user |
|
135 | * @return \phpbu\App\Cli\Executable\Rsync |
||
136 | */ |
||
137 | public function fromUser(string $user) : Rsync |
||
142 | |||
143 | 10 | /** |
|
144 | * Set source host. |
||
145 | 10 | * |
|
146 | 10 | * @param string $host |
|
147 | * @return \phpbu\App\Cli\Executable\Rsync |
||
148 | */ |
||
149 | public function fromHost(string $host) : Rsync |
||
154 | |||
155 | 5 | /** |
|
156 | * Set source path. |
||
157 | 5 | * |
|
158 | 5 | * @param string $path |
|
159 | * @return \phpbu\App\Cli\Executable\Rsync |
||
160 | */ |
||
161 | public function fromPath(string $path) : Rsync |
||
166 | |||
167 | 4 | /** |
|
168 | * Use compression. |
||
169 | 4 | * |
|
170 | 4 | * @param bool $bool |
|
171 | * @return \phpbu\App\Cli\Executable\Rsync |
||
172 | */ |
||
173 | public function compressed(bool $bool) : Rsync |
||
178 | |||
179 | 4 | /** |
|
180 | * Sync to host. |
||
181 | 4 | * |
|
182 | 4 | * @param string $host |
|
183 | * @return \phpbu\App\Cli\Executable\Rsync |
||
184 | */ |
||
185 | public function toHost(string $host) : Rsync |
||
190 | |||
191 | 11 | /** |
|
192 | * Set path to sync to. |
||
193 | 11 | * |
|
194 | 11 | * @param string $path |
|
195 | 11 | * @return \phpbu\App\Cli\Executable\Rsync |
|
196 | */ |
||
197 | 11 | public function toPath(string $path) : Rsync |
|
202 | |||
203 | 8 | /** |
|
204 | 1 | * Set user to connect as. |
|
205 | * |
||
206 | * @param string $user |
||
207 | 7 | * @return \phpbu\App\Cli\Executable\Rsync |
|
208 | */ |
||
209 | public function toUser(string $user) : Rsync |
||
214 | 2 | ||
215 | 2 | /** |
|
216 | 2 | * Exclude files. |
|
217 | 2 | * |
|
218 | * @param array $excludes |
||
219 | 7 | * @return \phpbu\App\Cli\Executable\Rsync |
|
220 | 7 | */ |
|
221 | public function exclude(array $excludes) : Rsync |
||
226 | 7 | ||
227 | /** |
||
228 | 7 | * Use --delete option. |
|
229 | * |
||
230 | * @param bool $bool |
||
231 | 9 | * @return \phpbu\App\Cli\Executable\Rsync |
|
232 | */ |
||
233 | public function removeDeleted(bool $bool) : Rsync |
||
238 | |||
239 | 11 | /** |
|
240 | * Rsync CommandLine generator. |
||
241 | 11 | * |
|
242 | * @return \SebastianFeldmann\Cli\CommandLine |
||
243 | 11 | * @throws \phpbu\App\Exception |
|
244 | */ |
||
245 | 2 | protected function createCommandLine() : CommandLine |
|
270 | |||
271 | /** |
||
272 | * Makes sure source and target are valid. |
||
273 | * |
||
274 | * @throws \phpbu\App\Exception |
||
275 | */ |
||
276 | protected function validateLocations() |
||
285 | |||
286 | /** |
||
287 | * Configure excludes. |
||
288 | * |
||
289 | * @param \SebastianFeldmann\Cli\Command\Executable $cmd |
||
290 | * @param array $excludes |
||
291 | */ |
||
292 | protected function configureExcludes(Cmd $cmd, array $excludes) |
||
298 | } |
||
299 |