46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Provisioning\Steps\Customer;
|
|
|
|
use App\Models\ProvisioningRun;
|
|
use App\Provisioning\StepResult;
|
|
use App\Services\Proxmox\ProxmoxClient;
|
|
|
|
class RegisterBackup extends CustomerStep
|
|
{
|
|
public function __construct(private ProxmoxClient $pve) {}
|
|
|
|
public function key(): string
|
|
{
|
|
return 'register_backup';
|
|
}
|
|
|
|
public function maxDuration(): int
|
|
{
|
|
return 120;
|
|
}
|
|
|
|
public function execute(ProvisioningRun $run): StepResult
|
|
{
|
|
if ($this->hasResource($run, 'backup_job_id')) {
|
|
return StepResult::advance();
|
|
}
|
|
|
|
$instance = $this->instance($run);
|
|
$schedule = 'daily 02:00';
|
|
|
|
// Create a real scheduled vzdump job on the host [E] before recording it.
|
|
$jobId = $this->pve->forHost($instance->host)
|
|
->createBackupJob((string) $run->context('node'), (int) $instance->vmid, $schedule);
|
|
|
|
$this->recordResource($run, $instance->host, 'backup_job_id', $jobId);
|
|
$instance->backups()->create([
|
|
'external_job_id' => $jobId,
|
|
'schedule' => $schedule,
|
|
'status' => 'scheduled',
|
|
]);
|
|
|
|
return StepResult::advance();
|
|
}
|
|
}
|