More code standards
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:
22
backup
22
backup
@ -1,26 +1,6 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
$autoload = null;
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
$autoloadFiles = [
|
|
||||||
__DIR__ . '/../vendor/autoload.php',
|
|
||||||
__DIR__ . '/../../../autoload.php',
|
|
||||||
__DIR__ . '/vendor/autoload.php'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($autoloadFiles as $autoloadFile) {
|
|
||||||
if (file_exists($autoloadFile)) {
|
|
||||||
$autoload = $autoloadFile;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $autoload) {
|
|
||||||
echo "Autoload file not found; try 'composer dump-autoload' first." . PHP_EOL;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
require $autoload;
|
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Composer\InstalledVersions;
|
use Composer\InstalledVersions;
|
||||||
|
|
||||||
|
45
composer.lock
generated
45
composer.lock
generated
@ -1666,25 +1666,29 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/deprecations",
|
"name": "doctrine/deprecations",
|
||||||
"version": "v1.1.0",
|
"version": "v1.1.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/doctrine/deprecations.git",
|
"url": "https://github.com/doctrine/deprecations.git",
|
||||||
"reference": "8cffffb2218e01f3b370bf763e00e81697725259"
|
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259",
|
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
|
||||||
"reference": "8cffffb2218e01f3b370bf763e00e81697725259",
|
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1|^8.0"
|
"php": "^7.1 || ^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"doctrine/coding-standard": "^9",
|
"doctrine/coding-standard": "^9",
|
||||||
"phpunit/phpunit": "^7.5|^8.5|^9.5",
|
"phpstan/phpstan": "1.4.10 || 1.10.15",
|
||||||
"psr/log": "^1|^2|^3"
|
"phpstan/phpstan-phpunit": "^1.0",
|
||||||
|
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
|
||||||
|
"psalm/plugin-phpunit": "0.18.4",
|
||||||
|
"psr/log": "^1 || ^2 || ^3",
|
||||||
|
"vimeo/psalm": "4.30.0 || 5.12.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
|
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
|
||||||
@ -1703,9 +1707,9 @@
|
|||||||
"homepage": "https://www.doctrine-project.org/",
|
"homepage": "https://www.doctrine-project.org/",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/doctrine/deprecations/issues",
|
"issues": "https://github.com/doctrine/deprecations/issues",
|
||||||
"source": "https://github.com/doctrine/deprecations/tree/v1.1.0"
|
"source": "https://github.com/doctrine/deprecations/tree/v1.1.1"
|
||||||
},
|
},
|
||||||
"time": "2023-05-29T18:55:17+00:00"
|
"time": "2023-06-03T09:27:29+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "doctrine/instantiator",
|
"name": "doctrine/instantiator",
|
||||||
@ -2532,22 +2536,23 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpdoc-parser",
|
"name": "phpstan/phpdoc-parser",
|
||||||
"version": "1.21.3",
|
"version": "1.22.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
||||||
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6"
|
"reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/b0c366dd2cea79407d635839d25423ba07c55dd6",
|
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c",
|
||||||
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6",
|
"reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2 || ^8.0"
|
"php": "^7.2 || ^8.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"doctrine/annotations": "^2.0",
|
||||||
"nikic/php-parser": "^4.15",
|
"nikic/php-parser": "^4.15",
|
||||||
"php-parallel-lint/php-parallel-lint": "^1.2",
|
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||||
"phpstan/extension-installer": "^1.0",
|
"phpstan/extension-installer": "^1.0",
|
||||||
@ -2572,22 +2577,22 @@
|
|||||||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
||||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.3"
|
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0"
|
||||||
},
|
},
|
||||||
"time": "2023-05-29T19:31:28+00:00"
|
"time": "2023-06-01T12:35:21+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpstan",
|
"name": "phpstan/phpstan",
|
||||||
"version": "1.10.15",
|
"version": "1.10.16",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpstan/phpstan.git",
|
"url": "https://github.com/phpstan/phpstan.git",
|
||||||
"reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd"
|
"reference": "352bdbb960bb523e3d71b834862589f910921c23"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/762c4dac4da6f8756eebb80e528c3a47855da9bd",
|
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/352bdbb960bb523e3d71b834862589f910921c23",
|
||||||
"reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd",
|
"reference": "352bdbb960bb523e3d71b834862589f910921c23",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -2636,7 +2641,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-05-09T15:28:01+00:00"
|
"time": "2023-06-05T08:21:46+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/php-code-coverage",
|
"name": "phpunit/php-code-coverage",
|
||||||
|
11
output.log
11
output.log
@ -1,11 +0,0 @@
|
|||||||
[2023-05-31T14:30:00.890085+00:00] app.INFO: Initialization complete [] []
|
|
||||||
[2023-05-31T14:30:00.946882+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/source'"] []
|
|
||||||
[2023-05-31T14:30:00.989664+00:00] rclone.INFO: Return code [0] []
|
|
||||||
[2023-05-31T14:30:00.989960+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/destination'"] []
|
|
||||||
[2023-05-31T14:30:01.047504+00:00] rclone.INFO: Return code [0] []
|
|
||||||
[2023-05-31T14:30:01.047810+00:00] rclone.INFO: Execute command ["'rclone' 'copy' 'temp/source' 'temp/destination' '--bwlimit' '6M'"] []
|
|
||||||
[2023-05-31T14:30:01.097485+00:00] rclone.INFO: Return code [0] []
|
|
||||||
[2023-05-31T14:30:01.097797+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/destination'"] []
|
|
||||||
[2023-05-31T14:30:01.142119+00:00] rclone.INFO: Return code [0] []
|
|
||||||
[2023-05-31T14:30:01.174134+00:00] notification.DEBUG: Sending ntfy notification {"topic":"backup","title":"Example","message":"Example\nFrom temp/source to temp/destination\nBackup started: May 31, 2023 14:30\nSource size: 8.00B\nDestination before: 8.00B\nDestination after: 8.00B\nDestination change : 0.00B\nBackup completed: May 31, 2023 14:30\n"} []
|
|
||||||
[2023-05-31T14:30:01.363282+00:00] notification.DEBUG: Result of ntfy notification ["{\"id\":\"iHfqUGi4dUsC\",\"time\":1685543401,\"expires\":1685586601,\"event\":\"message\",\"topic\":\"backup\",\"title\":\"Example\",\"message\":\"Example\\nFrom temp/source to temp/destination\\nBackup started: May 31, 2023 14:30\\nSource size: 8.00B\\nDestination before: 8.00B\\nDestination after: 8.00B\\nDestination change : 0.00B\\nBackup completed: May 31, 2023 14:30\"}\n"] []
|
|
25
src/App.php
25
src/App.php
@ -8,11 +8,25 @@ use Monolog\Logger;
|
|||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Application class
|
||||||
|
*
|
||||||
|
* Mostly working as a register pattern for the logging and configuration.
|
||||||
|
*
|
||||||
|
* @author Jens True <jens.chr.true@gmail.com>
|
||||||
|
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
* @link https://jcktrue.dk
|
||||||
|
*/
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
protected Logger $logger;
|
protected Logger $logger;
|
||||||
protected array $config;
|
protected array $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance providing a config file
|
||||||
|
*
|
||||||
|
* @param string $configFile Relative or full path to YML config.
|
||||||
|
*/
|
||||||
function __construct(string $configFile)
|
function __construct(string $configFile)
|
||||||
{
|
{
|
||||||
$this->config = Yaml::parseFile($configFile);
|
$this->config = Yaml::parseFile($configFile);
|
||||||
@ -26,12 +40,21 @@ class App
|
|||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the full configuration
|
||||||
|
*
|
||||||
|
* @return array Full configuration structure
|
||||||
|
*/
|
||||||
function getConfig() : array
|
function getConfig() : array
|
||||||
{
|
{
|
||||||
return $this->config;
|
return $this->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the logger instance.
|
||||||
|
*
|
||||||
|
* @return Logger Instance of logger
|
||||||
|
*/
|
||||||
function getLogger() : Logger
|
function getLogger() : Logger
|
||||||
{
|
{
|
||||||
return $this->logger;
|
return $this->logger;
|
||||||
|
@ -9,7 +9,13 @@ use Symfony\Component\Process\Exception\ProcessFailedException;
|
|||||||
|
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
/**
|
||||||
|
* Wrapper for the rclone command line utility
|
||||||
|
*
|
||||||
|
* Installation of rclone is required.
|
||||||
|
* Configuration of the mounts must be done before use.
|
||||||
|
* Tested using rclone v1.53.3-DEV
|
||||||
|
*/
|
||||||
class Rclone
|
class Rclone
|
||||||
{
|
{
|
||||||
use LoggerAwareTrait;
|
use LoggerAwareTrait;
|
||||||
@ -24,6 +30,14 @@ class Rclone
|
|||||||
|
|
||||||
protected string $version = "";
|
protected string $version = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* Default it looks for "rclone" on the path.
|
||||||
|
* But the path can be configured to be absolute.
|
||||||
|
*
|
||||||
|
* @param string $rclonePath Relative or absolute path
|
||||||
|
*/
|
||||||
function __construct(string $rclonePath = "rclone")
|
function __construct(string $rclonePath = "rclone")
|
||||||
{
|
{
|
||||||
$this->rclonePath = $rclonePath;
|
$this->rclonePath = $rclonePath;
|
||||||
@ -44,17 +58,35 @@ class Rclone
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rclone version
|
||||||
|
*
|
||||||
|
* @return string Version string
|
||||||
|
*/
|
||||||
function getVersion(): string
|
function getVersion(): string
|
||||||
{
|
{
|
||||||
return $this->version;
|
return $this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the size of a mount/path
|
||||||
|
*
|
||||||
|
* @return int Size in bytes
|
||||||
|
*/
|
||||||
function getSize(string $path): int
|
function getSize(string $path): int
|
||||||
{
|
{
|
||||||
$output = $this->exec('size', ['--json', $path]);
|
$output = $this->exec('size', ['--json', $path]);
|
||||||
return (int)json_decode($output)->bytes;
|
return (int)json_decode($output)->bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy from src to dest
|
||||||
|
*
|
||||||
|
* @param $src Source mount and path
|
||||||
|
* @param $dest Destination mount and path
|
||||||
|
* @param $bandwidth Bandwidth limit provided as string
|
||||||
|
* @return string Stdout from command
|
||||||
|
*/
|
||||||
function copy(string $src, string $dest, string $bandwidth = null): string
|
function copy(string $src, string $dest, string $bandwidth = null): string
|
||||||
{
|
{
|
||||||
$options = array();
|
$options = array();
|
||||||
|
@ -6,8 +6,20 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFilter;
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Twig extension
|
||||||
|
*
|
||||||
|
* Additional formatters for templates
|
||||||
|
*
|
||||||
|
* @author Jens True <jens.chr.true@gmail.com>
|
||||||
|
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
|
||||||
|
* @link https://jcktrue.dk
|
||||||
|
*/
|
||||||
class AppExtension extends AbstractExtension
|
class AppExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Extend the filters
|
||||||
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
Reference in New Issue
Block a user