#4870 -- Allow selectable backup format for automated backups.

This commit is contained in:
Buster "Silver Eagle" Neece 2022-06-05 01:06:21 -05:00
parent af97ed952d
commit 64e7a81083
No known key found for this signature in database
GPG Key ID: F1D2E64A0005E80E
4 changed files with 81 additions and 8 deletions

View File

@ -57,6 +57,16 @@
:options="storageLocationOptions"></b-form-select>
</template>
</b-wrapped-form-group>
<b-wrapped-form-group class="col-md-6" id="edit_form_backup_format" :field="$v.form.backup_format">
<template #label="{lang}">
<translate :key="lang">Backup Format</translate>
</template>
<template #default="props">
<b-form-radio-group stacked :id="props.id" v-model="props.field.$model"
:options="formatOptions"></b-form-radio-group>
</template>
</b-wrapped-form-group>
</b-form-row>
</b-form-fieldset>
</modal-form>
@ -104,7 +114,8 @@ export default {
'backup_time_code': {},
'backup_exclude_media': {},
'backup_keep_copies': {},
'backup_storage_location': {}
'backup_storage_location': {},
'backup_format': {},
}
},
computed: {
@ -113,7 +124,23 @@ export default {
},
storageLocationOptions() {
return objectToFormOptions(this.storageLocations);
}
},
formatOptions() {
return [
{
value: 'zip',
text: 'Zip',
},
{
value: 'tgz',
text: 'TarGz'
},
{
value: 'tzst',
text: 'ZStd'
}
];
},
},
methods: {
open() {
@ -137,7 +164,8 @@ export default {
backup_time_code: null,
backup_exclude_media: null,
backup_keep_copies: null,
backup_storage_location: null
backup_storage_location: null,
backup_format: null,
};
},
close() {

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Entity\Migration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220605052847 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add selectable automatic backup format.';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE settings ADD backup_format VARCHAR(255) DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE settings DROP backup_format');
}
}

View File

@ -624,6 +624,23 @@ class Settings implements Stringable
$this->backup_storage_location = $backupStorageLocation;
}
#[
OA\Property(description: "The output format for the automated backup.", example: 'zip'),
ORM\Column(nullable: true),
Groups(self::GROUP_BACKUP)
]
protected ?string $backup_format = null;
public function getBackupFormat(): ?string
{
return $this->backup_format;
}
public function setBackupFormat(?string $backup_format): void
{
$this->backup_format = $backup_format;
}
#[
OA\Property(
description: "The UNIX timestamp when automated backup was last run.",

View File

@ -99,9 +99,9 @@ class RunBackupTask extends AbstractTask
return;
}
$now_utc = CarbonImmutable::now('UTC');
$nowUtc = CarbonImmutable::now('UTC');
$threshold = $now_utc->subDay()->getTimestamp();
$threshold = $nowUtc->subDay()->getTimestamp();
$last_run = $settings->getBackupLastRun();
if ($last_run <= $threshold) {
@ -110,7 +110,7 @@ class RunBackupTask extends AbstractTask
if (null !== $backupTimecode && '' !== $backupTimecode) {
$isWithinTimecode = false;
$backupDt = Entity\StationSchedule::getDateTime($backupTimecode, $now_utc);
$backupDt = Entity\StationSchedule::getDateTime($backupTimecode, $nowUtc);
/** @var CarbonInterface[] $backupTimesToCheck */
$backupTimesToCheck = [
@ -121,7 +121,7 @@ class RunBackupTask extends AbstractTask
foreach ($backupTimesToCheck as $backupStart) {
$backupEnd = $backupStart->addMinutes(15);
if ($now_utc->between($backupStart, $backupEnd)) {
if ($nowUtc->between($backupStart, $backupEnd)) {
$isWithinTimecode = true;
break;
}
@ -138,9 +138,11 @@ class RunBackupTask extends AbstractTask
$storageLocationId = null;
}
$pathExt = $settings->getBackupFormat() ?? 'zip';
$message = new Message\BackupMessage();
$message->storageLocationId = $storageLocationId;
$message->path = 'automatic_backup_' . gmdate('Ymd_His') . '.zip';
$message->path = 'automatic_backup_' . $nowUtc->format('Ymd_His') . '.' . $pathExt;
$message->excludeMedia = $settings->getBackupExcludeMedia();
$this->messageBus->dispatch($message);