@@ -107,12 +107,61 @@
{/if}
+
+
+
+
对象清理异常
+
删除意图已从用户保留份数中移除;这里单独跟踪仍需在对象存储收敛的清理债务。
+
+
+
+ {if ($cleanup_debt_error|default:'') != ''}
+ {$cleanup_debt_error|escape}
+ {elseif $cleanup_debt|default:false}
+
+
清理债务{$cleanup_debt.summary.count} 个对象
+
待人工处理{$cleanup_debt.summary.attention_count} 个对象
+
占用空间{$cleanup_debt.summary.bytes} B
+
+ {if $cleanup_debt.items|@count > 0}
+
+
+ | 备份 | 用户 / 实例 | 状态 | 删除代次 | 对象大小 | 操作 |
+
+ {foreach $cleanup_debt.items as $item}
+
+ | #{$item.id} {$item.name|escape} {$item.error_code|escape} |
+ 用户 #{$item.user_id} 实例 #{$item.source_instance_id} |
+ {if $item.state == 'delete_attention'}需人工处理{else}自动核对中{/if} |
+ 总计 {$item.delete_generation} 本轮 {$item.cycle_attempts} / 3 |
+ {$item.object_size_bytes} B |
+ {if $item.can_retry}{else}等待系统核对{/if} |
+
+ {/foreach}
+
+
+
+ {if $cleanup_debt.pagination.total_pages > 1}
+
+
+ 第 {$cleanup_debt.pagination.page} / {$cleanup_debt.pagination.total_pages} 页
+
+
+ {/if}
+ {else}
+ 当前没有对象清理异常。
+ {/if}
+ {/if}
+
+
+
- 当前功能边界
本阶段只建立安全、可验证的对象存储配置基础。
+ 运行边界
云备份使用精确对象身份;Bucket 生命周期只作为控制面之外的最后兜底。
- 保存 S3 Endpoint、Region、Bucket、前缀和寻址方式,并加密保存访问凭据。
- 使用签名的 HeadBucket 请求验证 Bucket 可达性和 s3:ListBucket 权限;测试不会写入对象。
- - 云备份上传、增量链、保留策略、加密备份和异地恢复尚未接入,等待对象存储配置稳定后单独开发。
+ - 云备份对象采用独立目录身份;版本控制 Bucket 会保存并按准确 version_id 删除,并需要 s3:GetObjectVersion / s3:DeleteObjectVersion 权限。
+ - Bucket 仍应配置“终止未完成 multipart”和“清理非当前版本/过期删除标记”的生命周期规则作为最后兜底。
@@ -230,4 +279,51 @@
})();
{/literal}
+{literal}{/literal}
+
{include file='admin/static_footer.tpl'}
diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl
index cc9676fa..ba78139f 100644
--- a/web/resources/views/venix/layout_assets.tpl
+++ b/web/resources/views/venix/layout_assets.tpl
@@ -1,2 +1,2 @@
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
-{assign var=venix_asset_version value='2026102801' scope='global'}
+{assign var=venix_asset_version value='2026102802' scope='global'}
diff --git a/web/sql/cloud.sql b/web/sql/cloud.sql
index c17dad4a..6f7ab813 100644
--- a/web/sql/cloud.sql
+++ b/web/sql/cloud.sql
@@ -599,12 +599,22 @@ CREATE TABLE cloud_instance_backups (
object_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
virtual_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
+ object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
+ object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
spec_json LONGTEXT NOT NULL,
sealed_storage_runtime LONGTEXT NOT NULL,
sealed_credential LONGTEXT DEFAULT NULL,
storage_revision BIGINT UNSIGNED NOT NULL,
active_job_id BIGINT UNSIGNED DEFAULT NULL,
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
+ delete_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
+ delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
+ delete_cycle_attempts TINYINT UNSIGNED NOT NULL DEFAULT 0,
+ delete_presence_confirmations TINYINT UNSIGNED NOT NULL DEFAULT 0,
+ delete_requested_at BIGINT UNSIGNED DEFAULT NULL,
+ delete_last_checked_at BIGINT UNSIGNED DEFAULT NULL,
+ delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
+ delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
ready_at BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
@@ -614,7 +624,8 @@ CREATE TABLE cloud_instance_backups (
UNIQUE KEY cloud_instance_backup_schedule (subscription_id, scheduled_for),
KEY cloud_instance_backup_source (source_instance_id, state, id),
KEY cloud_instance_backup_owner (user_id, id),
- KEY cloud_instance_backup_operation (last_operation_id)
+ KEY cloud_instance_backup_operation (last_operation_id),
+ KEY cloud_instance_backup_delete_due (state, delete_next_check_at, id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- A user-owned, durable deployment source promoted from one automatic cloud
-- backup. The backing backup row remains the sole owner of the immutable S3
diff --git a/web/tests/CloudAutomaticBackupRetentionGraceTest.php b/web/tests/CloudAutomaticBackupRetentionGraceTest.php
index f0749ef0..4d9df209 100644
--- a/web/tests/CloudAutomaticBackupRetentionGraceTest.php
+++ b/web/tests/CloudAutomaticBackupRetentionGraceTest.php
@@ -100,12 +100,22 @@ namespace {
$table->integer('object_size_bytes');
$table->integer('virtual_size_bytes');
$table->string('sha256');
+ $table->string('object_etag')->default('');
+ $table->string('object_version_id')->default('');
$table->text('spec_json');
$table->text('sealed_storage_runtime');
$table->text('sealed_credential')->nullable();
$table->integer('storage_revision');
$table->integer('active_job_id')->nullable();
$table->string('last_operation_id')->nullable();
+ $table->string('delete_operation_id')->nullable();
+ $table->integer('delete_generation')->default(0);
+ $table->integer('delete_cycle_attempts')->default(0);
+ $table->integer('delete_presence_confirmations')->default(0);
+ $table->integer('delete_requested_at')->nullable();
+ $table->integer('delete_last_checked_at')->nullable();
+ $table->integer('delete_next_check_at')->default(0);
+ $table->integer('delete_attention_at')->nullable();
$table->string('error_code');
$table->integer('scheduled_for')->nullable();
$table->integer('ready_at')->nullable();
@@ -118,6 +128,9 @@ namespace {
$table->increments('id');
$table->integer('backup_id')->unique();
$table->string('state');
+ $table->string('error_code')->default('');
+ $table->integer('deleted_at')->nullable();
+ $table->integer('updated_at')->default(0);
});
foreach (['cloud_backup_restores', 'cloud_backup_recoveries'] as $tableName) {
$schema->create($tableName, static function (Blueprint $table): void {
@@ -192,6 +205,7 @@ namespace {
'object_key' => 'virt/vm-backups/' . $suffix . '/system.qcow2',
'object_size_bytes' => 1024, 'virtual_size_bytes' => 2048,
'sha256' => str_repeat('a', 64),
+ 'object_etag' => '', 'object_version_id' => '',
'spec_json' => json_encode([
'managed' => true, 'os_source' => 'cloud_template',
'os_name' => 'Debian 13', 'login_name' => 'root',
@@ -199,6 +213,9 @@ namespace {
], JSON_THROW_ON_ERROR),
'sealed_storage_runtime' => $sealedRuntime,
'sealed_credential' => 'sealed-credential', 'storage_revision' => 1,
+ 'delete_generation' => 0, 'delete_cycle_attempts' => 0,
+ 'delete_presence_confirmations' => 0,
+ 'delete_next_check_at' => 0,
'error_code' => '', 'scheduled_for' => $now - 1000,
'ready_at' => $now - 900, 'created_at' => $now - 1000,
'updated_at' => $now - 1000,
@@ -217,6 +234,17 @@ namespace {
$newSubscription(15, [$now - 3 * 86400]),
'ordinary-expired'
);
+ $debt = $newBackup(
+ $newSubscription(16, [$now - 3 * 86400]),
+ 'cleanup-debt'
+ );
+ $debt->state = 'delete_uncertain';
+ $debt->object_etag = '"debt-etag"';
+ $debt->object_version_id = 'debt-version';
+ $debt->delete_generation = 1;
+ $debt->delete_cycle_attempts = 1;
+ $debt->delete_next_check_at = 0;
+ $debt->save();
$capsule->table('cloud_deployment_snapshots')->insert([
'backup_id' => (int) $expired->id,
'state' => 'ready',
@@ -228,24 +256,34 @@ namespace {
&& CloudAutomaticBackupService::withinRecoveryGrace($renewed, $now),
'Recovery eligibility did not follow the paid period plus three-day grace.');
$history = [];
- $stack = HandlerStack::create(new MockHandler([new Response(204)]));
+ $stack = HandlerStack::create(new MockHandler([
+ new Response(404),
+ new Response(200, [
+ 'Content-Length' => '1024',
+ 'ETag' => '"fresh-etag"',
+ 'x-amz-version-id' => 'fresh-version',
+ ]),
+ new Response(204),
+ ]));
$stack->push(Middleware::history($history));
$client = new CloudObjectStorageS3Client(new Client(['handler' => $stack]));
- $removed = CloudAutomaticBackupService::pruneRetention(10, $now, $client);
+ $removed = CloudAutomaticBackupService::pruneRetention(1, $now, $client);
- foreach ([$paid, $insideGrace, $expired, $renewed, $ordinaryExpired]
+ foreach ([$paid, $insideGrace, $expired, $renewed, $ordinaryExpired, $debt]
as $backup) {
$backup->refresh();
}
- $assert($removed === 1
+ $assert($removed === 2
&& (string) $paid->state === 'ready'
&& (string) $insideGrace->state === 'ready'
&& (string) $expired->state === 'ready'
&& (string) $renewed->state === 'ready'
&& (string) $ordinaryExpired->state === 'deleted'
- && count($history) === 1
- && $history[0]['request']->getMethod() === 'DELETE',
- 'Automatic backups were not retained through grace or were pruned after promotion to a cloud snapshot.');
+ && (string) $debt->state === 'deleted'
+ && count($history) === 3
+ && array_map(static fn ($item): string =>
+ $item['request']->getMethod(), $history) === ['HEAD', 'HEAD', 'DELETE'],
+ 'Cleanup debt starved fresh retention work or entitlement grace was not preserved.');
echo "Automatic backup entitlement grace retention tests passed.\n";
}
diff --git a/web/tests/CloudDeploymentSnapshotServiceTest.php b/web/tests/CloudDeploymentSnapshotServiceTest.php
index 4c19b050..0a24a31c 100644
--- a/web/tests/CloudDeploymentSnapshotServiceTest.php
+++ b/web/tests/CloudDeploymentSnapshotServiceTest.php
@@ -95,12 +95,22 @@ namespace {
$table->integer('object_size_bytes');
$table->integer('virtual_size_bytes');
$table->string('sha256');
+ $table->string('object_etag')->default('');
+ $table->string('object_version_id')->default('');
$table->text('spec_json');
$table->text('sealed_storage_runtime');
$table->text('sealed_credential')->nullable();
$table->integer('storage_revision');
$table->integer('active_job_id')->nullable();
$table->string('last_operation_id')->nullable();
+ $table->string('delete_operation_id')->nullable();
+ $table->integer('delete_generation')->default(0);
+ $table->integer('delete_cycle_attempts')->default(0);
+ $table->integer('delete_presence_confirmations')->default(0);
+ $table->integer('delete_requested_at')->nullable();
+ $table->integer('delete_last_checked_at')->nullable();
+ $table->integer('delete_next_check_at')->default(0);
+ $table->integer('delete_attention_at')->nullable();
$table->string('error_code');
$table->integer('ready_at')->nullable();
$table->integer('created_at');
@@ -208,6 +218,8 @@ namespace {
$backup->object_size_bytes = 1024;
$backup->virtual_size_bytes = 2048;
$backup->sha256 = str_repeat(dechex(($id % 15) + 1), 64);
+ $backup->object_etag = '';
+ $backup->object_version_id = '';
$backup->spec_json = json_encode([
'managed' => true,
'os_source' => 'cloud_template',
@@ -220,6 +232,10 @@ namespace {
$backup->storage_revision = 1;
$backup->active_job_id = null;
$backup->last_operation_id = null;
+ $backup->delete_generation = 0;
+ $backup->delete_cycle_attempts = 0;
+ $backup->delete_presence_confirmations = 0;
+ $backup->delete_next_check_at = 0;
$backup->error_code = '';
$backup->ready_at = $now;
$backup->created_at = $backup->updated_at = $now;
@@ -398,13 +414,21 @@ namespace {
$deleted = CloudDeploymentSnapshotService::delete(
(string) $snapshot->snapshot_key,
$actor,
- $client([new Response(204)], $history)
+ $client([
+ new Response(200, [
+ 'Content-Length' => '1024',
+ 'ETag' => '"snapshot-etag"',
+ 'x-amz-version-id' => 'snapshot-version',
+ ]),
+ new Response(204),
+ ], $history)
);
$good->refresh();
$assert(($deleted['state'] ?? '') === 'deleted'
&& (string) $good->state === 'deleted'
- && count($history) === 1
- && $history[0]['request']->getMethod() === 'DELETE',
+ && count($history) === 2
+ && $history[0]['request']->getMethod() === 'HEAD'
+ && $history[1]['request']->getMethod() === 'DELETE',
'Cloud snapshot deletion did not converge its backing object.');
$uncertainBackup = $newBackup(15, 7, 3);
@@ -415,14 +439,24 @@ namespace {
$uncertain = CloudDeploymentSnapshotService::delete(
(string) $uncertainSnapshot->snapshot_key,
$actor,
- $client([new ConnectException(
- 'timeout', new Request('DELETE', 'https://objects.example.com')
- )], $uncertainHistory)
+ $client([
+ new Response(200, [
+ 'Content-Length' => '1024',
+ 'ETag' => '"uncertain-etag"',
+ 'x-amz-version-id' => 'uncertain-version',
+ ]),
+ new ConnectException(
+ 'timeout', new Request('DELETE', 'https://objects.example.com')
+ ),
+ ], $uncertainHistory)
);
$assert(($uncertain['state'] ?? '') === 'delete_uncertain'
- && count($uncertainHistory) === 1
- && $uncertainHistory[0]['request']->getMethod() === 'DELETE',
+ && count($uncertainHistory) === 2
+ && $uncertainHistory[1]['request']->getMethod() === 'DELETE',
'Unknown object deletion was not reflected by the cloud snapshot.');
+ $uncertainBackup->refresh();
+ $uncertainBackup->delete_next_check_at = 0;
+ $uncertainBackup->save();
$reconcileHistory = [];
$reconciled = CloudDeploymentSnapshotService::delete(
(string) $uncertainSnapshot->snapshot_key,
diff --git a/web/tests/CloudFreshSchemaContractTest.php b/web/tests/CloudFreshSchemaContractTest.php
index d51ef32c..ea3e7e74 100644
--- a/web/tests/CloudFreshSchemaContractTest.php
+++ b/web/tests/CloudFreshSchemaContractTest.php
@@ -22,7 +22,7 @@ $assert(stripos($schema, 'compatibility import') === false
$assert(!preg_match('/\bengine_[A-Za-z0-9_]*\b/', $schema),
'cloud.sql retained an engine-prefixed identifier.');
$assert(str_contains($setup,
- "SCHEMA_VERSION = 'go-agent-wss-v11-peer-migration-v2'")
+ "SCHEMA_VERSION = 'go-agent-wss-v12-object-cleanup-v1'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'Outbound Agent schema must reject the incompatible earlier Go database.');
$assert(str_contains($schema,
@@ -89,6 +89,21 @@ $assert(str_contains($schema,
&& str_contains($setup,
"'cloud_job_backup_recovery'"),
'Fresh schema is missing portable-backup catalog or restore reservation constraints.');
+$assert(str_contains($schema,
+ 'object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
+ && str_contains($schema,
+ 'object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL')
+ && str_contains($schema,
+ 'delete_generation INT UNSIGNED NOT NULL DEFAULT 0')
+ && str_contains($schema,
+ 'delete_cycle_attempts TINYINT UNSIGNED NOT NULL DEFAULT 0')
+ && str_contains($schema,
+ 'delete_presence_confirmations TINYINT UNSIGNED NOT NULL DEFAULT 0')
+ && str_contains($schema,
+ 'KEY cloud_instance_backup_delete_due (state, delete_next_check_at, id)')
+ && str_contains($setup, "'object_etag', 'object_version_id'")
+ && str_contains($setup, "'cloud_instance_backup_delete_due'"),
+ 'Fresh backup schema is missing exact-version cleanup debt fields or index.');
$assert(str_contains($schema,
'CREATE TABLE cloud_backup_period_entitlements (')
&& str_contains($schema,
diff --git a/web/tests/CloudObjectStorageAdminContractTest.php b/web/tests/CloudObjectStorageAdminContractTest.php
index 8fab835b..07c71362 100644
--- a/web/tests/CloudObjectStorageAdminContractTest.php
+++ b/web/tests/CloudObjectStorageAdminContractTest.php
@@ -31,6 +31,11 @@ foreach (['config' => 'save', 'test' => 'test', 'disable' => 'disable'] as $path
$assert(str_contains($routes, $needle),
'Object-storage mutation lost SuperAdmin/CSRF middleware: ' . $action);
}
+$assert(str_contains($routes,
+ "get('/object-storage/cleanup-debts', 'App\\Controllers\\Admin\\ObjectStorageController:cleanupDebt')")
+ && str_contains($routes,
+ "post('/object-storage/cleanup-debts/{backup_id:[0-9]+}/retry', 'App\\Controllers\\Admin\\ObjectStorageController:retryCleanup')->add(new SuperAdmin())"),
+ 'Object cleanup debt list or protected manual retry route is missing.');
$assert(str_contains($sidebar, 'href="/admin/object-storage"')
&& str_contains($sidebar, '