Fix handling for backups; correctly send along ignored files & directories
This commit is contained in:
parent
b6a0cca0f9
commit
00b0d30c60
8 changed files with 31 additions and 16 deletions
|
@ -87,7 +87,9 @@ class BackupController extends ClientApiController
|
||||||
}
|
}
|
||||||
|
|
||||||
$backup = $this->initiateBackupService
|
$backup = $this->initiateBackupService
|
||||||
->setIgnoredFiles($request->input('ignored'))
|
->setIgnoredFiles(
|
||||||
|
explode(PHP_EOL, $request->input('ignored') ?? '')
|
||||||
|
)
|
||||||
->handle($server, $request->input('name'));
|
->handle($server, $request->input('name'));
|
||||||
|
|
||||||
return $this->fractal->item($backup)
|
return $this->fractal->item($backup)
|
||||||
|
|
|
@ -22,7 +22,7 @@ class StoreBackupRequest extends ClientApiRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'nullable|string|max:255',
|
'name' => 'nullable|string|max:255',
|
||||||
'ignore' => 'nullable|string',
|
'ignored' => 'nullable|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ class ReportBackupCompleteRequest extends FormRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'successful' => 'boolean',
|
'successful' => 'boolean',
|
||||||
'checksum' => 'string|required_if:successful,true',
|
'checksum' => 'nullable|string|required_if:successful,true',
|
||||||
'size' => 'numeric|required_if:successful,true',
|
'size' => 'nullable|numeric|required_if:successful,true',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
* @property int $server_id
|
* @property int $server_id
|
||||||
* @property int $uuid
|
* @property int $uuid
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $ignored_files
|
* @property string[] $ignored_files
|
||||||
* @property string $disk
|
* @property string $disk
|
||||||
* @property string|null $sha256_hash
|
* @property string|null $sha256_hash
|
||||||
* @property int $bytes
|
* @property int $bytes
|
||||||
|
@ -45,6 +45,7 @@ class Backup extends Model
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'bytes' => 'int',
|
'bytes' => 'int',
|
||||||
|
'ignored_files' => 'array',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +70,7 @@ class Backup extends Model
|
||||||
'server_id' => 'bail|required|numeric|exists:servers,id',
|
'server_id' => 'bail|required|numeric|exists:servers,id',
|
||||||
'uuid' => 'required|uuid',
|
'uuid' => 'required|uuid',
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'ignored_files' => 'string',
|
'ignored_files' => 'array',
|
||||||
'disk' => 'required|string',
|
'disk' => 'required|string',
|
||||||
'sha256_hash' => 'nullable|string',
|
'sha256_hash' => 'nullable|string',
|
||||||
'bytes' => 'numeric',
|
'bytes' => 'numeric',
|
||||||
|
|
|
@ -29,7 +29,7 @@ class DaemonBackupRepository extends DaemonRepository
|
||||||
[
|
[
|
||||||
'json' => [
|
'json' => [
|
||||||
'uuid' => $backup->uuid,
|
'uuid' => $backup->uuid,
|
||||||
'ignored_files' => explode(PHP_EOL, $backup->ignored_files),
|
'ignored_files' => $backup->ignored_files,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Pterodactyl\Services\Backups;
|
||||||
|
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
use Pterodactyl\Models\Backup;
|
use Pterodactyl\Models\Backup;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
@ -13,7 +14,7 @@ use Pterodactyl\Repositories\Wings\DaemonBackupRepository;
|
||||||
class InitiateBackupService
|
class InitiateBackupService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string|null
|
* @var string[]|null
|
||||||
*/
|
*/
|
||||||
private $ignoredFiles;
|
private $ignoredFiles;
|
||||||
|
|
||||||
|
@ -52,12 +53,23 @@ class InitiateBackupService
|
||||||
/**
|
/**
|
||||||
* Sets the files to be ignored by this backup.
|
* Sets the files to be ignored by this backup.
|
||||||
*
|
*
|
||||||
* @param string|null $ignored
|
* @param string[]|null $ignored
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setIgnoredFiles(?string $ignored)
|
public function setIgnoredFiles(?array $ignored)
|
||||||
{
|
{
|
||||||
$this->ignoredFiles = $ignored;
|
if (is_array($ignored)) {
|
||||||
|
foreach ($ignored as $value) {
|
||||||
|
Assert::string($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the ignored files to be any values that are not empty in the array. Don't use
|
||||||
|
// the PHP empty function here incase anything that is "empty" by default (0, false, etc.)
|
||||||
|
// were passed as a file or folder name.
|
||||||
|
$this->ignoredFiles = is_null($ignored) ? [] : array_filter($ignored, function ($value) {
|
||||||
|
return strlen($value) > 0;
|
||||||
|
});
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +91,7 @@ class InitiateBackupService
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'uuid' => Uuid::uuid4()->toString(),
|
'uuid' => Uuid::uuid4()->toString(),
|
||||||
'name' => trim($name) ?: sprintf('Backup at %s', CarbonImmutable::now()->toDateTimeString()),
|
'name' => trim($name) ?: sprintf('Backup at %s', CarbonImmutable::now()->toDateTimeString()),
|
||||||
'ignored_files' => $this->ignoredFiles ?? '',
|
'ignored_files' => is_array($this->ignoredFiles) ? array_values($this->ignoredFiles) : [],
|
||||||
'disk' => 'local',
|
'disk' => 'local',
|
||||||
], true, true);
|
], true, true);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { rawDataToServerBackup, ServerBackup } from '@/api/server/backups/getServerBackups';
|
import { rawDataToServerBackup, ServerBackup } from '@/api/server/backups/getServerBackups';
|
||||||
import http from '@/api/http';
|
import http from '@/api/http';
|
||||||
|
|
||||||
export default (uuid: string, name?: string, ignore?: string): Promise<ServerBackup> => {
|
export default (uuid: string, name?: string, ignored?: string): Promise<ServerBackup> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
http.post(`/api/client/servers/${uuid}/backups`, {
|
http.post(`/api/client/servers/${uuid}/backups`, {
|
||||||
name, ignore,
|
name, ignored,
|
||||||
})
|
})
|
||||||
.then(({ data }) => resolve(rawDataToServerBackup(data)))
|
.then(({ data }) => resolve(rawDataToServerBackup(data)))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
|
|
|
@ -33,7 +33,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
|
||||||
</div>
|
</div>
|
||||||
<div className={'mb-6'}>
|
<div className={'mb-6'}>
|
||||||
<FormikFieldWrapper
|
<FormikFieldWrapper
|
||||||
name={'ignore'}
|
name={'ignored'}
|
||||||
label={'Ignored Files & Directories'}
|
label={'Ignored Files & Directories'}
|
||||||
description={`
|
description={`
|
||||||
Enter the files or folders to ignore while generating this backup. Leave blank to use
|
Enter the files or folders to ignore while generating this backup. Leave blank to use
|
||||||
|
@ -43,7 +43,7 @@ const ModalContent = ({ ...props }: RequiredModalProps) => {
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
<FormikField
|
<FormikField
|
||||||
name={'contents'}
|
name={'ignored'}
|
||||||
component={'textarea'}
|
component={'textarea'}
|
||||||
className={'input-dark h-32'}
|
className={'input-dark h-32'}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue