addArgument( 'config', InputArgument::REQUIRED, 'Configuration file' ); } /** * Start the backup process. * * 1. Read the configuration file. * 2. For each configured backup entry * 1. Get the size of the source * 2. Get the size of the destination * 3. Perform the backup * 4. Get the new size of the destination * 5. Send push notifications. * 3. Report final success */ protected function execute(InputInterface $input, OutputInterface $output): int { $sio = new SymfonyStyle($input, $output); $sio->title('Start backup process'); try { $app = new App((string)$input->getArgument('config')); } catch (\Throwable $e) { $sio->error('Configuration error:' . $e->getMessage()); return Command::FAILURE; } $rclone = new Rclone((string)$app->getConfig('rclone.path')); $rclone->setLogger($app->getLogger()->withName('rclone')); $notification = new Notification(); /** @var array> */ $notificationConfig = $app->getConfig('notification'); $notification->loadMany($notificationConfig); /** @var array */ $templateConfig = $app->getConfig('templates'); $render = new Twig($templateConfig); /** @var array{title: string, source: string, destination: string}[] */ $backupElements = $app->getConfig('backup'); /** @var array{title: string, source: string, destination: string} $conf */ foreach ($sio->progressIterate($backupElements) as $conf) { $title = $conf['title']; try { $template = array(); $template['config'] = $conf; $template['start'] = new DateTime(); $template['source_size'] = $rclone->getSize($conf['source']); $template['rclone_version'] = $rclone->getVersion(); $template['destination_size_before'] = $rclone->getSize($conf['destination']); /** @var array */ $rcloneOptions = $app->getConfig('rclone.options'); $rclone->copy($conf['source'], $conf['destination'], $rcloneOptions); $template['destination_size_after'] = $rclone->getSize($conf['destination']); $template['end'] = new DateTime(); $message = $render->render('notify', $template); } catch (\Exception $e) { $message = $e->getMessage(); $sio->error($message); } $notification->send($title, $message); } $sio->success("Complete"); return Command::SUCCESS; } }