Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

pterodactyl/panel

8314 stars
2 code files
View pterodactyl/panel on GitHub

app/Console/Commands/Maintenance/CleanServiceBackupFilesCommand.php

Open in GitHub
use SplFileInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
 
class CleanServiceBackupFilesCommand extends Command
{
const BACKUP_THRESHOLD_MINUTES = 5;
 
protected $description = 'Clean orphaned .bak files created when modifying services.';
 
protected $disk;
 
protected $signature = 'p:maintenance:clean-service-backups';
 
public function __construct(FilesystemFactory $filesystem)
{
parent::__construct();
 
$this->disk = $filesystem->disk();
}
 
public function handle()
{
$files = $this->disk->files('services/.bak');
 
collect($files)->each(function (SplFileInfo $file) {
$lastModified = Carbon::createFromTimestamp($this->disk->lastModified($file->getPath()));
if ($lastModified->diffInMinutes(Carbon::now()) > self::BACKUP_THRESHOLD_MINUTES) {
$this->disk->delete($file->getPath());
$this->info(trans('command/messages.maintenance.deleting_service_backup', ['file' => $file->getFilename()]));
}
});
}
}

app/Console/Kernel.php

Open in GitHub
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
 
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule)
{
//
$schedule->command('p:maintenance:clean-service-backups')->daily();
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.