Skip to content

Commit e722a8d

Browse files
author
Frank Karlitschek
committed
boilerplate code for restore
1 parent c20403d commit e722a8d

File tree

7 files changed

+197
-2
lines changed

7 files changed

+197
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ A backup app that enables admins to create backups of a Nextcloud instance and a
44

55
## OCC call
66
sudo -u www-data ./occ backup:create /home/frank/test-backup --password 12345
7+
sudo -u www-data ./occ backup:restore /home/frank/test-backup --password 12345
78

89

910
## OCS call
1011
curl -H "OCS-APIREQUEST: true" -X POST http://frank:OJYTQ-HJTIJ-LPLDY-ROWFK@dev/nextcloud-dev/server/ocs/v2.php/apps/backup/api/v1/create -d "path=/home/frank/test-backup" -d "password=12345"
12+
curl -H "OCS-APIREQUEST: true" -X POST http://frank:OJYTQ-HJTIJ-LPLDY-ROWFK@dev/nextcloud-dev/server/ocs/v2.php/apps/backup/api/v1/restore -d "path=/home/frank/test-backup" -d "password=12345"

appinfo/info.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</dependencies>
1414

1515
<commands>
16-
<command>OCA\Backup\Command\Generate</command>
16+
<command>OCA\Backup\Command\CreateCommand</command>
17+
<command>OCA\Backup\Command\RestoreCommand</command>
1718
</commands>
1819
</info>

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
return [
2525
'ocs' => [
2626
['name' => 'API#createBackup', 'url' => '/api/v1/create', 'verb' => 'POST'],
27+
['name' => 'API#restoreBackup', 'url' => '/api/v1/restore', 'verb' => 'POST'],
2728
],
2829
];

lib/Backup/Restore.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2017 Frank Karlitschek <frank@karlitschek.de>
4+
*
5+
* @author Frank Karlitschek <frank@karlitchek.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Backup\Backup;
25+
26+
use OCA\Backup\AppInfo\Application;
27+
use OCP\AppFramework\Http;
28+
use OCP\AppFramework\Http\DataResponse;
29+
use OCP\AppFramework\OCSController;
30+
use OCP\AppFramework\Utility\ITimeFactory;
31+
use OCP\IRequest;
32+
33+
class Restore {
34+
35+
/** @var path */
36+
protected $path;
37+
38+
/** @var password */
39+
protected $password;
40+
41+
/**
42+
* @param string $path
43+
*/
44+
public function __construct($path) {
45+
$this->path = $path;
46+
}
47+
48+
/**
49+
* @param string $password
50+
*/
51+
public function password($password) {
52+
$this->password = $password;
53+
}
54+
55+
/**
56+
* @param string $dbtype
57+
* @param string $dbname
58+
* @param string $dbuser
59+
* @param string $dbpassword
60+
* @param string $dbhost
61+
* @param string $path
62+
*/
63+
private function restoreDump($dbtype,$dbname,$dbuser,$dbpassword,$dbhost,$path) {
64+
}
65+
66+
/**
67+
* @param string $path
68+
*/
69+
private function copydata($path) {
70+
}
71+
72+
/**
73+
* @param string $path
74+
*/
75+
private function copyconfig($path) {
76+
}
77+
78+
/**
79+
* @param string $path
80+
*/
81+
private function readmeta($path) {
82+
}
83+
84+
/**
85+
*/
86+
public function restore() {
87+
\OC::$server->getLogger()->warning('Restore backup! Path:'.$this->path.' Password:'.$this->password,['app' => 'backup',]);
88+
}
89+
}

lib/Command/Generate.php renamed to lib/Command/CreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use Symfony\Component\Console\Input\InputOption;
3232
use Symfony\Component\Console\Output\OutputInterface;
3333

34-
class Generate extends Command {
34+
class CreateCommand extends Command {
3535

3636
/**
3737
*/

lib/Command/RestoreCommand.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2017 Frank Karlitschek <frank@karlitschek.de>
4+
*
5+
* @author Frank Karlitschek <frank@karlitschek.de>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Backup\Command;
25+
26+
use OCA\Backup\Backup\Restore;
27+
use OCA\Backup\AppInfo\Application;
28+
use Symfony\Component\Console\Command\Command;
29+
use Symfony\Component\Console\Input\InputArgument;
30+
use Symfony\Component\Console\Input\InputInterface;
31+
use Symfony\Component\Console\Input\InputOption;
32+
use Symfony\Component\Console\Output\OutputInterface;
33+
34+
class RestoreCommand extends Command {
35+
36+
/**
37+
*/
38+
public function __construct() {
39+
parent::__construct();
40+
}
41+
42+
protected function configure() {
43+
$this
44+
->setName('backup:restore')
45+
->setDescription('Restore a backup of the instance')
46+
->addArgument(
47+
'path',
48+
InputArgument::REQUIRED,
49+
'The path where the backup should be restored from'
50+
)
51+
->addOption(
52+
'password',
53+
'pass',
54+
InputOption::VALUE_REQUIRED,
55+
'Optionally password for an encrypted backup',
56+
''
57+
)
58+
;
59+
}
60+
61+
/**
62+
* @param InputInterface $input
63+
* @param OutputInterface $output
64+
* @return int
65+
*/
66+
protected function execute(InputInterface $input, OutputInterface $output) {
67+
68+
$path = $input->getArgument('path');
69+
70+
if ($path == '') {
71+
$output->writeln('Backup path not defined');
72+
return 1;
73+
}
74+
75+
$password = $input->getOption('password');
76+
if ($password == '') {
77+
$output->writeln('Password not specified');
78+
return 1;
79+
}
80+
81+
$backup = new \OCA\Backup\Backup\Restore($path);
82+
$backup -> password($password);
83+
$backup -> restore();
84+
85+
return 0;
86+
}
87+
}

lib/Controller/APIController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,19 @@ public function createBackup($path, $password) {
5151

5252
return new DataResponse();
5353
}
54+
55+
/**
56+
* @param string $path
57+
* @param string $password
58+
* @return DataResponse
59+
*/
60+
public function restoreBackup($path, $password) {
61+
$backup = new \OCA\Backup\Backup\Restore($path);
62+
$backup -> password($password);
63+
$backup -> restore();
64+
65+
return new DataResponse();
66+
}
67+
68+
5469
}

0 commit comments

Comments
 (0)