Skip to content

Commit

Permalink
updateupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 25, 2024
1 parent 75807c3 commit 8950a33
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 4 additions & 2 deletions web/app/Console/Commands/RunBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function handle()
$backup->status = 'pending';
$backup->save();
} else {
$this->info('Backup already exists for ' . $hostingSubscription->domain);
$this->info('Created before: ' . $findBackup->created_at->diffForHumans());
$this->error('Backup already exists for ' . $hostingSubscription->domain);
$this->error('Created before: ' . $findBackup->created_at->diffForHumans());
}
}
}
Expand All @@ -64,6 +64,7 @@ public function handle()
if ($getPendingBackups->count() > 0) {
foreach ($getPendingBackups as $pendingBackup) {
$pendingBackup->startBackup();
$this->info('Backup started.. ');
}
}

Expand All @@ -72,6 +73,7 @@ public function handle()
if ($getRunningBackups->count() > 0) {
foreach ($getRunningBackups as $runningBackup) {
$runningBackup->checkBackup();
$this->info('Checking backup status...');
}
}

Expand Down
2 changes: 2 additions & 0 deletions web/app/Filament/Resources/BackupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources;

use App\Filament\Enums\BackupStatus;
use App\Filament\Enums\BackupType;
use App\Filament\Resources\BackupResource\Pages;
use app\Filament\Resources\BackupResource\Widgets\BackupStats;
Expand Down Expand Up @@ -65,6 +66,7 @@ public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('process_id'),
Tables\Columns\TextColumn::make('backup_type'),
Tables\Columns\TextColumn::make('backupRelated'),
Tables\Columns\BadgeColumn::make('status')
Expand Down
27 changes: 23 additions & 4 deletions web/app/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,41 @@ protected function backupRelated() : Attribute

public function checkBackup()
{
if ($this->status == 'processing') {
if ($this->status == BackupStatus::Processing) {

$backupDoneFile = $this->path.'/backup.done';
if (file_exists($backupDoneFile)) {
$this->size = filesize($this->filepath);
$this->status = 'completed';
$this->completed = true;
$this->completed_at = now();
$this->save();
return [
'status' => 'completed',
'message' => 'Backup completed'
];
}

$checkProcess = shell_exec('ps -p ' . $this->process_id . ' | grep ' . $this->process_id);
if (Str::contains($checkProcess, $this->process_id)) {
return [
'status' => 'processing',
'message' => 'Backup is still processing'
];
} else {
$this->status = 'failed';
$this->save();
return [
'status' => 'failed',
'message' => 'Backup failed'
];
}
}
}

public function startBackup()
{

if ($this->status == 'processing') {
if ($this->status == BackupStatus::Processing) {
return [
'status' => 'processing',
'message' => 'Backup is already processing'
Expand Down Expand Up @@ -138,7 +157,7 @@ public function startBackup()

$pid = shell_exec('bash '.$backupTempScript.' >> ' . $backupLogFilePath . ' & echo $!');
$pid = intval($pid);

if ($pid > 0 && is_numeric($pid)) {

$this->path = $backupPath;
Expand Down

0 comments on commit 8950a33

Please sign in to comment.