Refactor + package updates + improve local backups

This commit is contained in:
Andras Bacsai
2023-08-10 15:52:54 +02:00
parent d2a4dbf283
commit e17f1935d2
30 changed files with 757 additions and 366 deletions

View File

@@ -2,6 +2,7 @@
const DATABASE_TYPES = ['postgresql'];
const VALID_CRON_STRINGS = [
'every_minute' => '* * * * *',
'hourly' => '0 * * * *',
'daily' => '0 0 * * *',
'weekly' => '0 0 * * 0',

View File

@@ -1,5 +1,6 @@
<?php
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\StandalonePostgresql;
use Visus\Cuid2\Cuid2;
@@ -24,5 +25,18 @@ function create_standalone_postgresql($environment_id, $destination_uuid): Stand
'destination_id' => $destination->id,
'destination_type' => $destination->getMorphClass(),
]);
}
/**
* Delete file locally on the filesystem.
* @param string $filename
* @param Server $server
* @return void
*/
function delete_backup_locally(string|null $filename, Server $server): void
{
if (empty($filename)) {
return;
}
instant_remote_process(["rm -f \"{$filename}\""], $server, throwError: false);
}

View File

@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
use Nubs\RandomNameGenerator\All;
use Poliander\Cron\CronExpression;
use Visus\Cuid2\Cuid2;
function application_configuration_dir(): string
@@ -166,3 +167,16 @@ function is_cloud(): bool
return !config('coolify.self_hosted');
}
function validate_cron_expression($expression_to_validate): bool
{
$isValid = false;
$expression = new CronExpression($expression_to_validate);
$isValid = $expression->isValid();
if (isset(VALID_CRON_STRINGS[$expression_to_validate])) {
$isValid = true;
}
return $isValid;
}