Add base migration and model for server backups

This commit is contained in:
Dane Everitt 2020-04-03 23:40:20 -07:00
parent f51d65229b
commit 17ec4efd3b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 127 additions and 0 deletions

59
app/Models/Backup.php Normal file
View File

@ -0,0 +1,59 @@
<?php
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property int $id
* @property int $uuid
* @property string $name
* @property string $contents
* @property string $disk
* @property string|null $sha256_hash
* @property int $bytes
* @property \Carbon\CarbonImmutable|null $completed_at
* @property \Carbon\CarbonImmutable $created_at
* @property \Carbon\CarbonImmutable $updated_at
* @property \Carbon\CarbonImmutable|null $deleted_at
*/
class Backup extends Model
{
use SoftDeletes;
/**
* @var string
*/
protected $table = 'backups';
/**
* @var bool
*/
protected $immutableDates = true;
/**
* @var array
*/
protected $casts = [
'id' => 'int',
'bytes' => 'int',
];
/**
* @var array
*/
protected $dates = [
'completed_at',
];
/**
* Returns dates from this model as immutable Carbon instances.
*
* @param mixed $value
* @return \Carbon\CarbonImmutable
*/
protected function asDateTime($value)
{
return $this->asImmutableDateTime($value);
}
}

29
config/backups.php Normal file
View File

@ -0,0 +1,29 @@
<?php
return [
// The backup driver to use for this Panel instance. All client generated server backups
// will be stored in this location by default. It is possible to change this once backups
// have been made, without losing data.
'driver' => env('APP_BACKUP_DRIVER', 'local'),
'disks' => [
// There is no configuration for the local disk for Wings. That configuration
// is determined by the Daemon configuration, and not the Panel.
'local' => [],
// Configuration for storing backups in Amazon S3.
's3' => [
'region' => '',
'access_key' => '',
'access_secret_key' => '',
// The S3 bucket to use for backups.
'bucket' => '',
// The location within the S3 bucket where backups will be stored. Backups
// are stored within a folder using the server's UUID as the name. Each
// backup for that server lives within that folder.
'location' => '',
],
],
];

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBackupsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('backups', function (Blueprint $table) {
$table->bigIncrements('id');
$table->char('uuid', 36);
$table->string('name');
$table->text('contents');
$table->string('disk');
$table->string('sha256_hash')->nullable();
$table->integer('bytes')->default(0);
$table->timestamp('completed_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('backups');
}
}