-
Notifications
You must be signed in to change notification settings - Fork 2
/
RestoreBackupRemoteHandler.php
66 lines (55 loc) · 2.58 KB
/
RestoreBackupRemoteHandler.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace DigipolisGent\Robo\Helpers\EventHandler\DefaultHandler;
use DigipolisGent\CommandBuilder\CommandBuilder;
use DigipolisGent\Robo\Helpers\EventHandler\AbstractBackupHandler;
use DigipolisGent\Robo\Helpers\Util\RemoteConfig;
use DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile;
use Symfony\Component\EventDispatcher\GenericEvent;
class RestoreBackupRemoteHandler extends AbstractBackupHandler
{
use \DigipolisGent\Robo\Helpers\Traits\RemoteDatabaseBackupTrait;
use \DigipolisGent\Robo\Helpers\Traits\RemoteFilesBackupTrait;
use \DigipolisGent\Robo\Task\Deploy\Tasks;
/**
* {@inheritDoc}
*/
public function handle(GenericEvent $event)
{
/** @var RemoteConfig $remoteConfig */
$remoteConfig = $event->getArgument('remoteConfig');
$remoteSettings = $remoteConfig->getRemoteSettings();
$options = $event->getArgument('options');
$timeouts = $event->getArgument('timeouts');
if (!$options['files'] && !$options['data']) {
$options['files'] = true;
$options['data'] = true;
}
$backupDir = $remoteSettings['backupsdir'] . '/' . $remoteSettings['time'];
$collection = $this->collectionBuilder();
if ($options['files']) {
$filesBackupFile = $this->backupFileName('.tar.gz', $remoteSettings['time']);
$collection
->taskSsh($remoteConfig->getHost(), new KeyFile($remoteConfig->getUser(), $remoteConfig->getPrivateKeyFile()))
->remoteDirectory($remoteSettings['filesdir'], true)
->timeout($timeouts['restore_files_backup'])
->exec(
(string) CommandBuilder::create('tar')
->addFlag('xkz')
->addFlag('f', $backupDir . '/' . $filesBackupFile)
);
}
// Restore the db backup.
if ($options['data']) {
$dbBackupFile = $this->backupFileName('.sql.gz', $remoteSettings['time']);
$collection
->taskSsh($remoteConfig->getHost(), new KeyFile($remoteConfig->getUser(), $remoteConfig->getPrivateKeyFile()))
->remoteDirectory($remoteConfig->getCurrentProjectRoot(), true)
->timeout($timeouts['restore_db_backup'])
->exec(
(string) CommandBuilder::create('vendor/bin/robo digipolis:database-restore')
->addOption('source', $backupDir . '/' . $dbBackupFile)
);
}
return $collection;
}
}