setName('backup:user:restore') ->setDescription('Restore a user from a user_migration export (see backup:user:backup)') ->addArgument('target', InputArgument::REQUIRED, 'Location name or id') ->addArgument('manifest', InputArgument::REQUIRED, 'Manifest path printed by backup:user:backup (users//)') ->addOption('mode', 'm', InputOption::VALUE_REQUIRED, 'replace or as-backup', UserRestoreService::MODE_REPLACE) ->setHelp(<<<'HELP' Never imports over a live account. Modes: replace (default) safety-exports the current account first, then deletes and recreates it fresh from the backup, under the same user id as-backup restores into a new account "-bak" (or "-bak-2", ...) instead, so an admin can compare and transfer by hand; Nextcloud cannot rename a user id, so the backup gets the new name, never the existing account Example: occ backup:user:restore offsite users/alice/20261005T120000Z-ab12cd34 occ backup:user:restore offsite users/alice/20261005T120000Z-ab12cd34 --mode=as-backup HELP); } protected function execute(InputInterface $input, OutputInterface $output): int { try { $target = $this->targets->get($input->getArgument('target')); $user = $this->userRestore->restoreUser($target, (string)$input->getArgument('manifest'), (string)$input->getOption('mode')); } catch (\Throwable $e) { $output->writeln('' . $e->getMessage() . ''); return 1; } $output->writeln('Restored ' . $user->getUID() . '.'); return 0; } }