39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Ui\System;
|
|
|
|
use Livewire\Component;
|
|
|
|
class BackupStatusCard extends Component
|
|
{
|
|
public ?string $lastAt = null;
|
|
public ?string $lastSize = null;
|
|
public ?string $lastDuration = null;
|
|
public ?bool $ok = null;
|
|
|
|
public function mount(): void { $this->load(); }
|
|
public function render() { return view('livewire.ui.system.backup-status-card'); }
|
|
public function refresh(): void { $this->load(true); }
|
|
|
|
public function runNow(): void
|
|
{
|
|
@shell_exec('nohup /usr/local/sbin/mailwolt-backup >/dev/null 2>&1 &');
|
|
$this->dispatch('toast', type:'info', title:'Backup gestartet');
|
|
}
|
|
|
|
protected function load(bool $force=false): void
|
|
{
|
|
// Example: parse a tiny status file your backup script writes.
|
|
$f = '/var/lib/mailwolt/backup.status';
|
|
if (is_file($f)) {
|
|
$lines = @file($f, FILE_IGNORE_NEW_LINES) ?: [];
|
|
foreach ($lines as $ln) {
|
|
if (str_starts_with($ln,'time=')) $this->lastAt = substr($ln,5);
|
|
if (str_starts_with($ln,'size=')) $this->lastSize = substr($ln,5);
|
|
if (str_starts_with($ln,'dur=')) $this->lastDuration = substr($ln,4);
|
|
if (str_starts_with($ln,'ok=')) $this->ok = (substr($ln,3) === '1');
|
|
}
|
|
}
|
|
}
|
|
}
|