This commit is contained in:
Bozhidar 2024-04-25 21:57:47 +03:00
parent 9c4c82ea98
commit ccfc0c936c
3 changed files with 39 additions and 3 deletions

View file

@ -58,9 +58,21 @@ class RunBackup extends Command
// }
// }
$findBackupsToday = Backup::where('created_at', '>=', Carbon::now()->subHours(24))
->first();
if (! $findBackupsToday) {
$backup = new Backup();
$backup->backup_type = 'full';
$backup->save();
} else {
$this->info('We already have a backup for today.');
}
// Check for pending backups
$getPendingBackups = Backup::where('status', 'pending')
->get();
if ($getPendingBackups->count() > 0) {
foreach ($getPendingBackups as $pendingBackup) {
$pendingBackup->startBackup();

View file

@ -130,7 +130,7 @@ class Backup extends Model
mkdir($backupTempPath);
}
if ($this->backup_type == 'system') {
if ($this->backup_type == 'full') {
// Export Phyre Panel database
$databaseBackupPath = $backupTempPath.'/database.sql';

View file

@ -9,12 +9,36 @@ use App\Models\Customer;
use App\Models\HostingPlan;
use App\Models\HostingSubscription;
use Faker\Factory;
use Illuminate\Support\Facades\Artisan;
use Tests\Feature\Api\ActionTestCase;
class BackupTest extends ActionTestCase
{
public function testSystemBackup()
public function testFullBackup()
{
Artisan::call('phyre:run-backup');
$findLastBackup = Backup::orderBy('id', 'asc')->first();
$this->assertNotEmpty($findLastBackup);
$this->assertNotEmpty($findLastBackup->id);
$this->assertNotEmpty($findLastBackup->created_at);
$this->assertSame($findLastBackup->backup_type, 'full');
$backupFinished = false;
for ($i = 0; $i < 100; $i++) {
$findLastBackup = Backup::orderBy('id', 'desc')->first();
$findLastBackup->checkBackup();
if ($findLastBackup->status == BackupStatus::Completed) {
$backupFinished = true;
break;
}
sleep(1);
}
$this->assertTrue($backupFinished);
$this->assertSame($findLastBackup->status, BackupStatus::Completed);
$this->assertNotEmpty($findLastBackup->filepath);
$this->assertTrue(file_exists($findLastBackup->filepath));
$backup = new Backup();
$checkCronJob = $backup->checkCronJob();
$this->assertTrue($checkCronJob);
@ -45,7 +69,7 @@ class BackupTest extends ActionTestCase
$hostingSubscription->save();
$backup = new Backup();
$backup->backup_type = 'system';
$backup->backup_type = 'full';
$backup->save();
$backupId = $backup->id;