|
| 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 | +} |
0 commit comments