More codestandards.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
24
composer.lock
generated
24
composer.lock
generated
@ -1528,16 +1528,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "twig/twig",
|
"name": "twig/twig",
|
||||||
"version": "v3.6.0",
|
"version": "v3.6.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/twigphp/Twig.git",
|
"url": "https://github.com/twigphp/Twig.git",
|
||||||
"reference": "106c170d08e8415d78be2d16c3d057d0d108262b"
|
"reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b",
|
"url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd",
|
||||||
"reference": "106c170d08e8415d78be2d16c3d057d0d108262b",
|
"reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -1583,7 +1583,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/twigphp/Twig/issues",
|
"issues": "https://github.com/twigphp/Twig/issues",
|
||||||
"source": "https://github.com/twigphp/Twig/tree/v3.6.0"
|
"source": "https://github.com/twigphp/Twig/tree/v3.6.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -1595,7 +1595,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-05-03T19:06:57+00:00"
|
"time": "2023-06-08T12:52:13+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "verifiedjoseph/ntfy-php-library",
|
"name": "verifiedjoseph/ntfy-php-library",
|
||||||
@ -3304,16 +3304,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "10.2.1",
|
"version": "10.2.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "599b33294350e8f51163119d5670512f98b0490d"
|
"reference": "1ab521b24b88b88310c40c26c0cc4a94ba40ff95"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/599b33294350e8f51163119d5670512f98b0490d",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1ab521b24b88b88310c40c26c0cc4a94ba40ff95",
|
||||||
"reference": "599b33294350e8f51163119d5670512f98b0490d",
|
"reference": "1ab521b24b88b88310c40c26c0cc4a94ba40ff95",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3385,7 +3385,7 @@
|
|||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||||
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
||||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.1"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -3401,7 +3401,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-06-05T05:15:51+00:00"
|
"time": "2023-06-11T06:15:20+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
notification:
|
notification:
|
||||||
domain: https://ntfy.jcktrue.dk
|
Ntfy:
|
||||||
topic: backup
|
domain: https://ntfy.jcktrue.dk
|
||||||
|
topic: backup
|
||||||
log: output.log
|
log: output.log
|
||||||
rclone:
|
rclone:
|
||||||
bwlimit: 6M
|
options:
|
||||||
|
bwlimit: 6M
|
||||||
backup:
|
backup:
|
||||||
- title: Example
|
- title: Example
|
||||||
source: temp/source
|
source: temp/source
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
@ -10,15 +11,15 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Twig\Loader\ArrayLoader;
|
use Twig\Loader\ArrayLoader;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Ntfy\Server;
|
use App\Notification\Notification;
|
||||||
use Ntfy\Message;
|
use App\Rclone\Rclone;
|
||||||
use Ntfy\Client;
|
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'backup',
|
||||||
|
description: 'Start backup to assigned buckets',
|
||||||
|
)]
|
||||||
class CommandBackup extends Command
|
class CommandBackup extends Command
|
||||||
{
|
{
|
||||||
public static $defaultName = "backup";
|
|
||||||
public static $defaultDescription = "Start backup to assigned buckets";
|
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->addArgument(
|
$this->addArgument(
|
||||||
@ -41,39 +42,38 @@ class CommandBackup extends Command
|
|||||||
return Command::FAILURE;
|
return Command::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rclone = new Rclone\Rclone();
|
$rclone = new Rclone();
|
||||||
$rclone->setLogger($app->getLogger()->withName('rclone'));
|
$rclone->setLogger($app->getLogger()->withName('rclone'));
|
||||||
|
|
||||||
$server = new Server($app->getConfig()['notification']['domain']);
|
$notification = new Notification();
|
||||||
$client = new Client($server);
|
$notification->loadMany($app->getConfig()['notification']);
|
||||||
|
|
||||||
$loader = new ArrayLoader($app->getConfig()['templates']);
|
$loader = new ArrayLoader($app->getConfig()['templates']);
|
||||||
$twig = new Environment($loader);
|
$twig = new Environment($loader);
|
||||||
$twig->addExtension(new Twig\AppExtension());
|
$twig->addExtension(new Twig\AppExtension());
|
||||||
|
|
||||||
foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) {
|
foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) {
|
||||||
$message = new Message();
|
$title = $conf['title'];
|
||||||
$message->topic($app->getConfig()['notification']['topic']);
|
$message = "";
|
||||||
$message->title($conf['title']);
|
|
||||||
try {
|
try {
|
||||||
$template = array();
|
$template = array();
|
||||||
$template['config'] = $conf;
|
$template['config'] = $conf;
|
||||||
$template['start'] = new DateTime();
|
$template['start'] = new DateTime();
|
||||||
$template['source_size'] = $rclone->getSize($conf['source']);
|
$template['source_size'] = $rclone->getSize($conf['source']);
|
||||||
|
$template['rclone_version'] = $rclone->getVersion();
|
||||||
$template['destination_size_before'] = $rclone->getSize($conf['destination']);
|
$template['destination_size_before'] = $rclone->getSize($conf['destination']);
|
||||||
|
|
||||||
$rclone->copy($conf['source'], $conf['destination'], "6M");
|
$template['stdout'] = $rclone->copy($conf['source'], $conf['destination'], $app->getConfig()['rclone']['options']);
|
||||||
|
|
||||||
$template['destination_size_after'] = $rclone->getSize($conf['destination']);
|
$template['destination_size_after'] = $rclone->getSize($conf['destination']);
|
||||||
$template['end'] = new DateTime();
|
$template['end'] = new DateTime();
|
||||||
|
|
||||||
$message->body($twig->render('notify', $template));
|
$message = $twig->render('notify', $template);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$message->body($e->getMessage());
|
$message = $e->getMessage();
|
||||||
$message->tags(["warning"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->send($message);
|
$notification->send($title, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sio->success("Complete");
|
$sio->success("Complete");
|
||||||
|
@ -2,17 +2,19 @@
|
|||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'show',
|
||||||
|
description: 'Show all backup entries.',
|
||||||
|
)]
|
||||||
class CommandShow extends Command
|
class CommandShow extends Command
|
||||||
{
|
{
|
||||||
public static $defaultName = "show";
|
|
||||||
public static $defaultDescription = "Show all backup entries";
|
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
$this->addArgument(
|
$this->addArgument(
|
||||||
|
31
src/Notification/Notification.php
Normal file
31
src/Notification/Notification.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notification;
|
||||||
|
|
||||||
|
class Notification
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @type NotificationInterface[] $notifiers
|
||||||
|
*/
|
||||||
|
public array $notifiers = array();
|
||||||
|
public function loadMany(array $config): void
|
||||||
|
{
|
||||||
|
foreach ($config as $key => $conf) {
|
||||||
|
$this->loadSingle($key, $conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadSingle(string $key, array $config): void
|
||||||
|
{
|
||||||
|
$class = "\App\Notification\\" . $key;
|
||||||
|
|
||||||
|
$this->notifiers[$key] = new $class($config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send(string $title, string $message): void
|
||||||
|
{
|
||||||
|
foreach ($this->notifiers as $notifier) {
|
||||||
|
$notifier->send($title, $message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/Notification/NotificationInterface.php
Normal file
8
src/Notification/NotificationInterface.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notification;
|
||||||
|
|
||||||
|
interface NotificationInterface
|
||||||
|
{
|
||||||
|
public function send(string $title, string $message): void;
|
||||||
|
}
|
32
src/Notification/Ntfy.php
Normal file
32
src/Notification/Ntfy.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notification;
|
||||||
|
|
||||||
|
use Ntfy\Server;
|
||||||
|
use Ntfy\Message;
|
||||||
|
use Ntfy\Client;
|
||||||
|
|
||||||
|
class Ntfy implements NotificationInterface
|
||||||
|
{
|
||||||
|
private array $config;
|
||||||
|
|
||||||
|
private \Ntfy\Server $server;
|
||||||
|
private \Ntfy\Client $client;
|
||||||
|
|
||||||
|
public function __construct(array $config)
|
||||||
|
{
|
||||||
|
$this->config = $config;
|
||||||
|
|
||||||
|
$this->server = new Server($config['domain']);
|
||||||
|
$this->client = new Client($this->server);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function send(string $title, string $message): void
|
||||||
|
{
|
||||||
|
$msg = new Message();
|
||||||
|
$msg->topic($this->config['topic']);
|
||||||
|
$msg->title($title);
|
||||||
|
$msg->body($message);
|
||||||
|
$this->client->send($msg);
|
||||||
|
}
|
||||||
|
}
|
@ -81,21 +81,28 @@ class Rclone
|
|||||||
/**
|
/**
|
||||||
* Copy from source to destination.
|
* Copy from source to destination.
|
||||||
*
|
*
|
||||||
* @param $src Source mount and path
|
* @param $src Source mount and path
|
||||||
* @param $dest Destination mount and path
|
* @param $dest Destination mount and path
|
||||||
* @param $bandwidth Bandwidth limit provided as string
|
* @param $additionalOptions strings[] Bandwidth limit provided as string
|
||||||
*
|
*
|
||||||
* @return string Stdout from command
|
* @return string Stdout from command
|
||||||
*/
|
*/
|
||||||
public function copy(string $src, string $dest, string $bandwidth = null): string
|
public function copy(string $src, string $dest, array $additionalOptions = array()): string
|
||||||
{
|
{
|
||||||
$options = array();
|
$options = array();
|
||||||
|
|
||||||
$options[] = $src;
|
$options[] = $src;
|
||||||
$options[] = $dest;
|
$options[] = $dest;
|
||||||
if ($bandwidth) {
|
foreach ($additionalOptions as $key => $value) {
|
||||||
$options[] = "--bwlimit";
|
if (strlen($key) == 1) {
|
||||||
$options[] = $bandwidth;
|
$options[] = '-' . $key;
|
||||||
|
$options[] = $value;
|
||||||
|
} elseif (strlen($key) > 2) {
|
||||||
|
$options[] = '--' . $key;
|
||||||
|
$options[] = $value;
|
||||||
|
} else {
|
||||||
|
$options[] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->exec('copy', $options);
|
return $this->exec('copy', $options);
|
||||||
|
Reference in New Issue
Block a user