addArgument( 'config', InputArgument::REQUIRED, 'Configuration file' ); } 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($app->getConfig('rclone.path')); $rclone->setLogger($app->getLogger()->withName('rclone')); $notification = new Notification(); $notification->loadMany($app->getConfig('notification')); $render = new Twig($app->getConfig('templates')); foreach ($sio->progressIterate($app->getConfig('backup')) as $conf) { $title = $conf['title']; try { $template = array(); $template['config'] = $conf; $template['start'] = new DateTime(); $template['source_size'] = $rclone->getSize((string)$conf['source']); $template['rclone_version'] = $rclone->getVersion(); $template['destination_size_before'] = $rclone->getSize((string)$conf['destination']); $rclone->copy((string)$conf['source'], (string)$conf['destination'], $app->getConfig('rclone.options')); $template['destination_size_after'] = $rclone->getSize((string)$conf['destination']); $template['end'] = new DateTime(); $message = $render->render('notify', $template); } catch (\Exception $e) { $message = $e->getMessage(); } $notification->send((string)$title, $message); } $sio->success("Complete"); return Command::SUCCESS; } }