Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 25, 2024
1 parent 9c4c82e commit ccfc0c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
12 changes: 12 additions & 0 deletions web/app/Console/Commands/RunBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,21 @@ public function handle()
// }
// }

$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();
Expand Down
2 changes: 1 addition & 1 deletion web/app/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function startBackup()
mkdir($backupTempPath);
}

if ($this->backup_type == 'system') {
if ($this->backup_type == 'full') {

// Export Phyre Panel database
$databaseBackupPath = $backupTempPath.'/database.sql';
Expand Down
28 changes: 26 additions & 2 deletions web/tests/Unit/BackupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,36 @@
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);
Expand Down Expand Up @@ -45,7 +69,7 @@ public function testSystemBackup()
$hostingSubscription->save();

$backup = new Backup();
$backup->backup_type = 'system';
$backup->backup_type = 'full';
$backup->save();

$backupId = $backup->id;
Expand Down

0 comments on commit ccfc0c9

Please sign in to comment.