addArgument('config', InputArgument::OPTIONAL, 'Configuration file', "config.yml"); } protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('Start backup!'); $output->writeln('Opening: '.$input->getArgument('config')); try { $config = Yaml::parseFile($input->getArgument('config')); } catch (ParseException $e) { $output->writeln('Unable to parse the YAML string: '. $e->getMessage()); } $rclone = new Rclone\Rclone(); $output->writeln("Rclone version: ". $rclone->getVersion()); $ntfy = new Ntfy\Ntfy($config['notification']['domain']); $loader = new \Twig\Loader\ArrayLoader($config['templates']); $twig = new \Twig\Environment($loader); $twig->addExtension(new Twig\AppExtension()); foreach ($config['backup'] as $conf) { try { $template['config'] = $conf; $template['start'] = new \DateTime(); $template['source_size'] = $rclone->getSize($conf['source']); $template['destination_size_before'] = $rclone->getSize($conf['destination']); $rclone->copy($conf['source'], $conf['destination'], "6M"); $template['destination_size_after'] = $rclone->getSize($conf['destination']); $template['end'] = new \DateTime(); $message = $twig->render('notify', $template); echo $message; } catch (\Throwable $e) { $message = $e->getMessage(); } $ntfy->send($config['notification']['topic'], $conf['title'], $message); } return Command::SUCCESS; } }