-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b265c15
commit 2325192
Showing
8 changed files
with
285 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Backup; | ||
use App\Models\HostingSubscription; | ||
use Illuminate\Console\Command; | ||
|
||
class RunBackup extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'phyre:run-backup'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Command description'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
// Delete backups older than 7 days | ||
$findBackupsForDeleting = Backup::where('created_at', '<', now()->subDays(7))->get(); | ||
foreach ($findBackupsForDeleting as $backup) { | ||
$backup->delete(); | ||
} | ||
|
||
$getBackups = Backup::where('backup_type', 'hosting_subscription')->get(); | ||
if ($getBackups->count() > 0) { | ||
foreach ($getBackups as $backup) { | ||
$status = $backup->startBackup(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Filament\Enums; | ||
|
||
use Filament\Support\Contracts\HasLabel; | ||
use JaOcero\RadioDeck\Contracts\HasDescriptions; | ||
use JaOcero\RadioDeck\Contracts\HasIcons; | ||
|
||
enum BackupType: string implements HasLabel, HasDescriptions, HasIcons | ||
{ | ||
|
||
case FULL_BACKUP = 'full'; | ||
case SYSTEM_BACKUP = 'system'; | ||
case DATABASE_BACKUP = 'database'; | ||
case HOSTING_SUBSCRIPTION_BACKUP = 'hosting_subscription'; | ||
public function getLabel(): ?string | ||
{ | ||
return match ($this) { | ||
self::FULL_BACKUP => 'Full Backup', | ||
self::SYSTEM_BACKUP => 'System Backup', | ||
self::DATABASE_BACKUP => 'Database Backup', | ||
self::HOSTING_SUBSCRIPTION_BACKUP => 'Hosting Subscription Backup', | ||
}; | ||
} | ||
|
||
public function getDescriptions(): ?string | ||
{ | ||
return match ($this) { | ||
self::FULL_BACKUP => 'A full backup is a complete copy of your website files and database. It is the best way to protect your website data.', | ||
self::SYSTEM_BACKUP => 'A system backup is a copy of your website files and system files. It is useful for restoring your website if there is a problem with the system files.', | ||
self::DATABASE_BACKUP => 'A database backup is a copy of your website database. It is useful for restoring your website if there is a problem with the database.', | ||
self::HOSTING_SUBSCRIPTION_BACKUP => 'A hosting subscription backup is a copy of your website files and database. It is useful for restoring your website if there is a problem with the hosting subscription.', | ||
}; | ||
} | ||
|
||
public function getIcons(): ?string | ||
{ | ||
return match ($this) { | ||
self::FULL_BACKUP => 'heroicon-o-inbox-stack', | ||
self::SYSTEM_BACKUP => 'heroicon-o-cog', | ||
self::DATABASE_BACKUP => 'phyre-mysql', | ||
self::HOSTING_SUBSCRIPTION_BACKUP => 'heroicon-o-server', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
web/database/migrations/2024_04_24_144158_create_backups_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('backups', function (Blueprint $table) { | ||
$table->id(); | ||
$table->bigInteger('hosting_subscription_id')->nullable(); | ||
$table->string('backup_type')->nullable(); | ||
$table->string('status')->nullable(); | ||
$table->string('path')->nullable(); | ||
$table->string('size')->nullable(); | ||
$table->string('disk')->nullable(); | ||
$table->longText('settings')->nullable(); | ||
|
||
|
||
$table->tinyInteger('queued')->nullable(); | ||
$table->timestamp('queued_at')->nullable(); | ||
|
||
$table->tinyInteger('started')->nullable(); | ||
$table->timestamp('started_at')->nullable(); | ||
|
||
$table->tinyInteger('completed')->nullable(); | ||
$table->timestamp('completed_at')->nullable(); | ||
|
||
$table->tinyInteger('failed')->nullable(); | ||
$table->timestamp('failed_at')->nullable(); | ||
|
||
$table->tinyInteger('cancelled')->nullable(); | ||
$table->timestamp('cancelled_at')->nullable(); | ||
|
||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('backups'); | ||
} | ||
}; |