Skip to content

Commit 951d92b

Browse files
committed
Store S3 upload_id in the database for backups
1 parent 9b01734 commit 951d92b

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct(BackupRepository $repository, BackupManager $backupM
4747
* @return \Illuminate\Http\JsonResponse
4848
*
4949
* @throws \Exception
50+
* @throws \Throwable
5051
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
5152
*/
5253
public function __invoke(Request $request, string $backup)
@@ -101,8 +102,12 @@ public function __invoke(Request $request, string $backup)
101102
)->getUri()->__toString();
102103
}
103104

104-
return new JsonResponse([
105+
// Set the upload_id on the backup in the database.
106+
$backup->forceFill([
105107
'upload_id' => $params['UploadId'],
108+
])->saveOrFail();
109+
110+
return new JsonResponse([
106111
'parts' => $parts,
107112
'part_size' => self::PART_SIZE,
108113
]);

app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function __invoke(ReportBackupCompleteRequest $request, string $backup)
7878
$params = [
7979
'Bucket' => $adapter->getBucket(),
8080
'Key' => sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid),
81-
'UploadId' => $request->input('upload_id'),
81+
'UploadId' => $backup->upload_id,
8282
];
8383

8484
// If the backup was not successful, send an AbortMultipartUpload request.

app/Models/Backup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @property string $disk
1515
* @property string|null $checksum
1616
* @property int $bytes
17+
* @property string|null $upload_id
1718
* @property \Carbon\CarbonImmutable|null $completed_at
1819
* @property \Carbon\CarbonImmutable $created_at
1920
* @property \Carbon\CarbonImmutable $updated_at
@@ -46,8 +47,8 @@ class Backup extends Model
4647
protected $casts = [
4748
'id' => 'int',
4849
'is_successful' => 'bool',
49-
'bytes' => 'int',
5050
'ignored_files' => 'array',
51+
'bytes' => 'int',
5152
];
5253

5354
/**
@@ -64,6 +65,7 @@ class Backup extends Model
6465
'is_successful' => true,
6566
'checksum' => null,
6667
'bytes' => 0,
68+
'upload_id' => null,
6769
];
6870

6971
/**
@@ -78,6 +80,7 @@ class Backup extends Model
7880
'disk' => 'required|string',
7981
'checksum' => 'nullable|string',
8082
'bytes' => 'numeric',
83+
'upload_id' => 'nullable|uuid',
8184
];
8285

8386
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddUploadIdColumnToBackupsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('backups', function (Blueprint $table) {
17+
$table->char('upload_id', 36)->nullable()->after('bytes');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('backups', function (Blueprint $table) {
29+
$table->dropColumn('upload_id');
30+
});
31+
}
32+
}

0 commit comments

Comments
 (0)