-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRsyncFilesToLocalHandler.php
43 lines (36 loc) · 1.48 KB
/
RsyncFilesToLocalHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace DigipolisGent\Robo\Helpers\EventHandler\DefaultHandler;
use DigipolisGent\Robo\Helpers\EventHandler\AbstractTaskEventHandler;
use DigipolisGent\Robo\Helpers\Util\RemoteConfig;
use Symfony\Component\EventDispatcher\GenericEvent;
class RsyncFilesToLocalHandler extends AbstractTaskEventHandler
{
/**
* {@inheritDoc}
*/
public function handle(GenericEvent $event)
{
/** @var RemoteConfig $remoteConfig */
$remoteConfig = $event->getArgument('remoteConfig');
$remoteSettings = $remoteConfig->getRemoteSettings();
$localSettings = $event->getArgument('localSettings');
$directory = $event->getArgument('directory');
$fileBackupConfig = $event->getArgument('fileBackupConfig');
$rsync = $this->taskRsync()
->rawArg('--rsh "ssh -o StrictHostKeyChecking=no -i `vendor/bin/robo digipolis:realpath ' . $remoteConfig->getPrivateKeyFile() . '`"')
->fromHost($remoteConfig->getHost())
->fromUser($remoteConfig->getUser())
->fromPath($remoteSettings['filesdir'] . '/' . $directory)
->toPath($localSettings['filesdir'] . '/' . $directory)
->archive()
->delete()
->rawArg('--copy-links --keep-dirlinks')
->compress()
->checksum()
->wholeFile();
foreach ($fileBackupConfig['exclude_from_backup'] as $exclude) {
$rsync->exclude($exclude);
}
return $rsync;
}
}