This commit is contained in:
Bozhidar 2024-05-02 11:55:21 +03:00
parent 4e19730e02
commit bb75a16428
4 changed files with 38 additions and 26 deletions

View file

@ -42,7 +42,7 @@ class RunBackup extends Command
if ($getPendingBackups->count() > 0) {
if ($getPendingBackups->count() > 1) {
$this->info('Multiple backups are pending..');
$this->info('Multiple backups are pending...');
} else {
foreach ($getPendingBackups as $pendingBackup) {
$pendingBackup->startBackup();

View file

@ -17,7 +17,7 @@ class RunHostingSubscriptionsBackup extends Command
*
* @var string
*/
protected $signature = 'phyre:run-hosting-subscriptions-backup';
protected $signature = 'phyre:run-hosting-subscriptions-backup-checks';
/**
* The console command description.
@ -37,26 +37,26 @@ class RunHostingSubscriptionsBackup extends Command
$backup->delete();
}
// Find Hosting Subscriptions
$findHostingSubscriptions = HostingSubscription::all();
if ($findHostingSubscriptions->count() > 0) {
foreach ($findHostingSubscriptions as $hostingSubscription) {
$findBackup = HostingSubscriptionBackup::where('hosting_subscription_id', $hostingSubscription->id)
->where('backup_type', 'full')
->where('created_at', '>=', Carbon::now()->subHours(24))
->first();
if (! $findBackup) {
$backup = new HostingSubscriptionBackup();
$backup->hosting_subscription_id = $hostingSubscription->id;
$backup->backup_type = 'full';
$backup->save();
} else {
$this->error('Backup already exists for ' . $hostingSubscription->domain);
$this->error('Created before: ' . $findBackup->created_at->diffForHumans());
}
}
}
// // Find Hosting Subscriptions
// $findHostingSubscriptions = HostingSubscription::all();
// if ($findHostingSubscriptions->count() > 0) {
// foreach ($findHostingSubscriptions as $hostingSubscription) {
//
// $findBackup = HostingSubscriptionBackup::where('hosting_subscription_id', $hostingSubscription->id)
// ->where('backup_type', 'full')
// ->where('created_at', '>=', Carbon::now()->subHours(24))
// ->first();
// if (! $findBackup) {
// $backup = new HostingSubscriptionBackup();
// $backup->hosting_subscription_id = $hostingSubscription->id;
// $backup->backup_type = 'full';
// $backup->save();
// } else {
// $this->error('Backup already exists for ' . $hostingSubscription->domain);
// $this->error('Created before: ' . $findBackup->created_at->diffForHumans());
// }
// }
// }
// Check for pending backups
@ -64,8 +64,8 @@ class RunHostingSubscriptionsBackup extends Command
->get();
if ($getPendingBackups->count() > 0) {
if ($getPendingBackups->count() > 3) {
$this->info('There are more than 3 pending backups. Please wait for them to finish.');
if ($getPendingBackups->count() > 1) {
$this->info('Multiple backups are pending...');
} else {
foreach ($getPendingBackups as $pendingBackup) {
$pendingBackup->startBackup();

View file

@ -7,6 +7,7 @@ use App\Filament\Resources\HostingPlanResource\Pages;
use App\Models\HostingPlan;
use App\Models\RemoteDatabaseServer;
use App\SupportedApplicationTypes;
use Filament\Actions\DeleteAction;
use Filament\Forms;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Select;
@ -250,6 +251,7 @@ class HostingPlanResource extends Resource
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([

View file

@ -65,7 +65,7 @@ class HostingSubscriptionBackup extends Model
public function checkCronJob()
{
$cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:run-hosting-subscriptions-backup';
$cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:run-hosting-subscriptions-backup-checks';
$findCronJob = CronJob::where('command', $cronJobCommand)->first();
if (! $findCronJob) {
$cronJob = new CronJob();
@ -73,8 +73,18 @@ class HostingSubscriptionBackup extends Model
$cronJob->command = $cronJobCommand;
$cronJob->user = 'root';
$cronJob->save();
return false;
}
$cronJobCommand = 'phyre-php /usr/local/phyre/web/artisan phyre:create-daily-full-hosting-subscriptions-backup';
$findCronJob = CronJob::where('command', $cronJobCommand)->first();
if (! $findCronJob) {
$cronJob = new CronJob();
$cronJob->schedule = '0 0 * * *';
$cronJob->command = $cronJobCommand;
$cronJob->user = 'root';
$cronJob->save();
}
return true;
}