Skip to content

Commit 17ec4ef

Browse files
committed
Add base migration and model for server backups
1 parent f51d652 commit 17ec4ef

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

app/Models/Backup.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Pterodactyl\Models;
4+
5+
use Illuminate\Database\Eloquent\SoftDeletes;
6+
7+
/**
8+
* @property int $id
9+
* @property int $uuid
10+
* @property string $name
11+
* @property string $contents
12+
* @property string $disk
13+
* @property string|null $sha256_hash
14+
* @property int $bytes
15+
* @property \Carbon\CarbonImmutable|null $completed_at
16+
* @property \Carbon\CarbonImmutable $created_at
17+
* @property \Carbon\CarbonImmutable $updated_at
18+
* @property \Carbon\CarbonImmutable|null $deleted_at
19+
*/
20+
class Backup extends Model
21+
{
22+
use SoftDeletes;
23+
24+
/**
25+
* @var string
26+
*/
27+
protected $table = 'backups';
28+
29+
/**
30+
* @var bool
31+
*/
32+
protected $immutableDates = true;
33+
34+
/**
35+
* @var array
36+
*/
37+
protected $casts = [
38+
'id' => 'int',
39+
'bytes' => 'int',
40+
];
41+
42+
/**
43+
* @var array
44+
*/
45+
protected $dates = [
46+
'completed_at',
47+
];
48+
49+
/**
50+
* Returns dates from this model as immutable Carbon instances.
51+
*
52+
* @param mixed $value
53+
* @return \Carbon\CarbonImmutable
54+
*/
55+
protected function asDateTime($value)
56+
{
57+
return $this->asImmutableDateTime($value);
58+
}
59+
}

config/backups.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
return [
4+
// The backup driver to use for this Panel instance. All client generated server backups
5+
// will be stored in this location by default. It is possible to change this once backups
6+
// have been made, without losing data.
7+
'driver' => env('APP_BACKUP_DRIVER', 'local'),
8+
9+
'disks' => [
10+
// There is no configuration for the local disk for Wings. That configuration
11+
// is determined by the Daemon configuration, and not the Panel.
12+
'local' => [],
13+
14+
// Configuration for storing backups in Amazon S3.
15+
's3' => [
16+
'region' => '',
17+
'access_key' => '',
18+
'access_secret_key' => '',
19+
20+
// The S3 bucket to use for backups.
21+
'bucket' => '',
22+
23+
// The location within the S3 bucket where backups will be stored. Backups
24+
// are stored within a folder using the server's UUID as the name. Each
25+
// backup for that server lives within that folder.
26+
'location' => '',
27+
],
28+
],
29+
];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateBackupsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('backups', function (Blueprint $table) {
17+
$table->bigIncrements('id');
18+
$table->char('uuid', 36);
19+
$table->string('name');
20+
$table->text('contents');
21+
$table->string('disk');
22+
$table->string('sha256_hash')->nullable();
23+
$table->integer('bytes')->default(0);
24+
$table->timestamp('completed_at')->nullable();
25+
$table->timestamps();
26+
$table->softDeletes();
27+
});
28+
}
29+
30+
/**
31+
* Reverse the migrations.
32+
*
33+
* @return void
34+
*/
35+
public function down()
36+
{
37+
Schema::dropIfExists('backups');
38+
}
39+
}

0 commit comments

Comments
 (0)