Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Extensions/Tasks/Schemas/CreateBackupSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getId(): string

public function runTask(Task $task): void
{
$this->initiateService->setIgnoredFiles(explode(PHP_EOL, $task->payload))->handle($task->server, null, true);
$this->initiateService->setIgnoredFiles(explode(PHP_EOL, $task->payload))->handle($task->server, null, true, true);
}

public function canCreate(Schedule $schedule): bool
Expand Down
4 changes: 4 additions & 0 deletions app/Listeners/Server/BackupCompletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class BackupCompletedListener
{
public function handle(BackupCompleted $event): void
{
if ($event->backup->is_automated && $event->backup->is_successful) {
return;
}

$event->backup->loadMissing('server');
$event->backup->server->loadMissing('user');

Expand Down
5 changes: 5 additions & 0 deletions app/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @property bool $is_successful
* @property string|null $upload_id
* @property bool $is_locked
* @property bool $is_automated
* @property-read Server $server
* @property-read BackupStatus $status
*
Expand All @@ -50,6 +51,7 @@
* @method static BackupQueryBuilder<static>|Backup whereIgnoredFiles($value)
* @method static BackupQueryBuilder<static>|Backup whereIsLocked($value)
* @method static BackupQueryBuilder<static>|Backup whereIsSuccessful($value)
* @method static BackupQueryBuilder<static>|Backup whereIsAutomated($value)
* @method static BackupQueryBuilder<static>|Backup whereName($value)
* @method static BackupQueryBuilder<static>|Backup whereServerId($value)
* @method static BackupQueryBuilder<static>|Backup whereUpdatedAt($value)
Expand All @@ -69,6 +71,7 @@ class Backup extends Model implements Validatable
protected $attributes = [
'is_successful' => false,
'is_locked' => false,
'is_automated' => false,
'checksum' => null,
'bytes' => 0,
'upload_id' => null,
Expand All @@ -82,6 +85,7 @@ class Backup extends Model implements Validatable
'uuid' => ['required', 'uuid'],
'is_successful' => ['boolean'],
'is_locked' => ['boolean'],
'is_automated' => ['boolean'],
'name' => ['required', 'string'],
'ignored_files' => ['array'],
'backup_host_id' => ['required', 'integer', 'exists:backup_hosts,id'],
Expand All @@ -96,6 +100,7 @@ protected function casts(): array
'id' => 'int',
'is_successful' => 'bool',
'is_locked' => 'bool',
'is_automated' => 'bool',
'ignored_files' => 'array',
'bytes' => 'int',
'completed_at' => 'immutable_datetime',
Expand Down
8 changes: 5 additions & 3 deletions app/Services/Backups/InitiateBackupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setIgnoredFiles(?array $ignored): self
* @throws TooManyBackupsException
* @throws TooManyRequestsHttpException
*/
public function handle(Server $server, ?string $name = null, bool $override = false): Backup
public function handle(Server $server, ?string $name = null, bool $override = false, bool $isAutomated = false): Backup
{
$limit = config('backups.throttles.limit');
$period = config('backups.throttles.period');
Expand Down Expand Up @@ -121,14 +121,16 @@ public function handle(Server $server, ?string $name = null, bool $override = fa
throw new Exception('Backup host has unknown backup adapter.');
}

return $this->connection->transaction(function () use ($backupHost, $schema, $server, $name) {
$backup = Backup::create([
return $this->connection->transaction(function () use ($backupHost, $schema, $server, $name, $isAutomated) {
/** @var Backup $backup */
$backup = Backup::query()->create([
'server_id' => $server->id,
'uuid' => Uuid::uuid4()->toString(),
'name' => trim($name) ?: sprintf('Backup at %s', now()->toDateTimeString()),
'ignored_files' => array_values($this->ignoredFiles ?? []),
'backup_host_id' => $backupHost->id,
'is_locked' => $this->isLocked,
'is_automated' => $isAutomated,
]);

$schema->createBackup($backup);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('backups', function (Blueprint $table) {
$table->boolean('is_automated')->default(false)->after('is_successful');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('backups', function (Blueprint $table) {
$table->dropColumn('is_automated');
});
}
};
Loading