adula 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +149 -18
- package/build/agent/AGENTS.template.md +4 -4
- package/build/agent/capabilities.md +22 -12
- package/build/agent/skills/adula-frontend-design/SKILL.md +6 -4
- package/build/agent/skills/idea-review/SKILL.md +2 -2
- package/build/commands/adula_assistant_prune.d.ts +10 -0
- package/build/commands/adula_assistant_prune.js +12 -0
- package/build/commands/adula_outbox.d.ts +10 -0
- package/build/commands/adula_outbox.js +11 -0
- package/build/commands/adula_restore_reconcile.d.ts +10 -0
- package/build/commands/adula_restore_reconcile.js +34 -0
- package/build/commands/adula_runtime_health.d.ts +10 -0
- package/build/commands/adula_runtime_health.js +27 -0
- package/build/commands/adula_uploads_prune.d.ts +10 -0
- package/build/commands/adula_uploads_prune.js +16 -0
- package/build/commands/app.d.ts +10 -0
- package/build/commands/app.js +64 -0
- package/build/commands/backup_create.d.ts +11 -0
- package/build/commands/backup_create.js +99 -0
- package/build/commands/backup_open.d.ts +16 -0
- package/build/commands/backup_open.js +48 -0
- package/build/commands/backup_restore_files.d.ts +11 -0
- package/build/commands/backup_restore_files.js +44 -0
- package/build/commands/backup_restore_test.d.ts +12 -0
- package/build/commands/backup_restore_test.js +188 -0
- package/build/commands/backup_seal.d.ts +12 -0
- package/build/commands/backup_seal.js +36 -0
- package/build/commands/backup_services.d.ts +33 -0
- package/build/commands/backup_services.js +6 -0
- package/build/commands/backup_verify.d.ts +9 -0
- package/build/commands/backup_verify.js +59 -0
- package/build/commands/backup_verify_snapshot.d.ts +10 -0
- package/build/commands/backup_verify_snapshot.js +37 -0
- package/build/commands/client.d.ts +16 -0
- package/build/commands/client.js +71 -0
- package/build/commands/doctor.js +21 -1
- package/build/commands/install.d.ts +8 -0
- package/build/commands/install.js +69 -45
- package/build/commands/main.d.ts +3 -2
- package/build/commands/main.js +32 -0
- package/build/commands/module_add.js +4 -20
- package/build/commands/resource.d.ts +2 -0
- package/build/commands/resource.js +12 -3
- package/build/commands/resource_migration.d.ts +15 -0
- package/build/commands/resource_migration.js +81 -0
- package/build/commands/resource_snapshot.d.ts +2 -0
- package/build/commands/resource_snapshot.js +21 -4
- package/build/commands/sla_evaluate.d.ts +14 -0
- package/build/commands/sla_evaluate.js +16 -0
- package/build/commands/ui.js +4 -2
- package/build/commands/ui_css.d.ts +9 -0
- package/build/commands/ui_css.js +19 -0
- package/build/commands/upgrade.d.ts +1 -1
- package/build/commands/upgrade.js +1 -1
- package/build/configure.js +1 -1
- package/build/database/migrations/1770000000020_two_factor.d.ts +5 -0
- package/build/database/migrations/1770000000020_two_factor.js +10 -0
- package/build/database/migrations/1770000000041_import_modes.d.ts +5 -0
- package/build/database/migrations/1770000000041_import_modes.js +10 -0
- package/build/database/migrations/1770000000042_sync_jobs.d.ts +5 -0
- package/build/database/migrations/1770000000042_sync_jobs.js +10 -0
- package/build/database/migrations/1770000000043_notification_channels.d.ts +5 -0
- package/build/database/migrations/1770000000043_notification_channels.js +10 -0
- package/build/database/migrations/1770000000044_channel_confirmations.d.ts +5 -0
- package/build/database/migrations/1770000000044_channel_confirmations.js +10 -0
- package/build/database/migrations/1770000000045_import_leases.d.ts +5 -0
- package/build/database/migrations/1770000000045_import_leases.js +10 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.d.ts +5 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.js +10 -0
- package/build/database/migrations/1770000000049_print_templates.d.ts +5 -0
- package/build/database/migrations/1770000000049_print_templates.js +10 -0
- package/build/database/migrations/1770000000051_comment_notifications.d.ts +5 -0
- package/build/database/migrations/1770000000051_comment_notifications.js +10 -0
- package/build/database/migrations/1770000000054_cloud_backups.d.ts +5 -0
- package/build/database/migrations/1770000000054_cloud_backups.js +10 -0
- package/build/database/migrations/1770000000055_ai_assistant.d.ts +5 -0
- package/build/database/migrations/1770000000055_ai_assistant.js +10 -0
- package/build/database/migrations/1770000000056_appearance.d.ts +5 -0
- package/build/database/migrations/1770000000056_appearance.js +10 -0
- package/build/index.d.ts +87 -11
- package/build/index.js +50 -7
- package/build/providers/adula_provider.d.ts +2 -0
- package/build/providers/adula_provider.js +7 -0
- package/build/src/admin/contracts.js +1 -1
- package/build/src/admin/controller.d.ts +14 -1
- package/build/src/admin/controller.js +91 -13
- package/build/src/admin/errors.d.ts +32 -0
- package/build/src/admin/errors.js +63 -1
- package/build/src/admin/presentation.d.ts +21 -2
- package/build/src/admin/resource/editor.d.ts +60 -0
- package/build/src/admin/resource/editor.js +345 -0
- package/build/src/admin/resource/export.d.ts +54 -0
- package/build/src/admin/resource/export.js +262 -0
- package/build/src/admin/resource/lifecycle.d.ts +23 -0
- package/build/src/admin/resource/lifecycle.js +91 -0
- package/build/src/admin/resource/query.d.ts +111 -0
- package/build/src/admin/resource/query.js +595 -0
- package/build/src/admin/resource/read.d.ts +109 -0
- package/build/src/admin/resource/read.js +388 -0
- package/build/src/admin/resource/shared.d.ts +93 -0
- package/build/src/admin/resource/shared.js +265 -0
- package/build/src/admin/resource/trash.d.ts +10 -0
- package/build/src/admin/resource/trash.js +56 -0
- package/build/src/admin/resource/write.d.ts +57 -0
- package/build/src/admin/resource/write.js +603 -0
- package/build/src/admin/resource_service.d.ts +80 -193
- package/build/src/admin/resource_service.js +81 -1343
- package/build/src/admin/resource_tools.d.ts +111 -0
- package/build/src/admin/resource_tools.js +139 -0
- package/build/src/ai/assistant.d.ts +100 -0
- package/build/src/ai/assistant.js +487 -0
- package/build/src/ai/client.d.ts +49 -0
- package/build/src/ai/client.js +85 -0
- package/build/src/ai/prompt.d.ts +23 -0
- package/build/src/ai/prompt.js +83 -0
- package/build/src/ai/settings.d.ts +56 -0
- package/build/src/ai/settings.js +214 -0
- package/build/src/ai/usage.d.ts +16 -0
- package/build/src/ai/usage.js +33 -0
- package/build/src/appearance/appearance.d.ts +134 -0
- package/build/src/appearance/appearance.js +461 -0
- package/build/src/appearance/colors.d.ts +43 -0
- package/build/src/appearance/colors.js +99 -0
- package/build/src/appearance/logo.d.ts +32 -0
- package/build/src/appearance/logo.js +112 -0
- package/build/src/attachments/attachment_service.d.ts +46 -2
- package/build/src/attachments/attachment_service.js +96 -4
- package/build/src/auth/actor_store.d.ts +5 -1
- package/build/src/auth/actor_store.js +8 -4
- package/build/src/auth/conditions.d.ts +5 -0
- package/build/src/auth/conditions.js +26 -3
- package/build/src/auth/sql.js +17 -5
- package/build/src/auth/two_factor.d.ts +96 -0
- package/build/src/auth/two_factor.js +259 -0
- package/build/src/backups/archive.d.ts +52 -0
- package/build/src/backups/archive.js +362 -0
- package/build/src/backups/cloud_backups.d.ts +133 -0
- package/build/src/backups/cloud_backups.js +650 -0
- package/build/src/backups/doctor.d.ts +7 -0
- package/build/src/backups/doctor.js +55 -0
- package/build/src/backups/providers.d.ts +81 -0
- package/build/src/backups/providers.js +470 -0
- package/build/src/collaboration/assignments.d.ts +59 -2
- package/build/src/collaboration/assignments.js +196 -74
- package/build/src/collaboration/record_collaboration.d.ts +21 -4
- package/build/src/collaboration/record_collaboration.js +126 -51
- package/build/src/collaboration/shared.d.ts +24 -0
- package/build/src/collaboration/shared.js +34 -0
- package/build/src/commands/app_scaffold.d.ts +72 -0
- package/build/src/commands/app_scaffold.js +285 -0
- package/build/src/commands/capabilities.js +35 -9
- package/build/src/commands/doctor.d.ts +24 -2
- package/build/src/commands/doctor.js +81 -6
- package/build/src/commands/gap_report.d.ts +1 -1
- package/build/src/commands/gap_report.js +2 -2
- package/build/src/commands/generator.d.ts +37 -1
- package/build/src/commands/generator.js +61 -18
- package/build/src/commands/snapshot.d.ts +24 -13
- package/build/src/commands/snapshot.js +54 -14
- package/build/src/commands/source_markers.d.ts +10 -0
- package/build/src/commands/source_markers.js +29 -0
- package/build/src/core/activity.d.ts +2 -0
- package/build/src/core/activity.js +7 -1
- package/build/src/core/administrators.d.ts +38 -0
- package/build/src/core/administrators.js +145 -0
- package/build/src/core/avatar_image.d.ts +33 -0
- package/build/src/core/avatar_image.js +278 -0
- package/build/src/core/html_sanitizer.d.ts +20 -0
- package/build/src/core/html_sanitizer.js +261 -0
- package/build/src/core/like.d.ts +5 -0
- package/build/src/core/like.js +5 -0
- package/build/src/core/lookups.d.ts +80 -0
- package/build/src/core/lookups.js +319 -0
- package/build/src/core/mail_settings.d.ts +83 -0
- package/build/src/core/mail_settings.js +274 -0
- package/build/src/core/mail_test.d.ts +16 -0
- package/build/src/core/mail_test.js +81 -6
- package/build/src/core/message_templates.d.ts +15 -2
- package/build/src/core/message_templates.js +81 -11
- package/build/src/core/module_seed.js +2 -1
- package/build/src/core/notification_channels.d.ts +235 -0
- package/build/src/core/notification_channels.js +660 -0
- package/build/src/core/roles.js +26 -9
- package/build/src/core/saved_views.d.ts +8 -1
- package/build/src/core/saved_views.js +91 -26
- package/build/src/core/sequences.d.ts +32 -0
- package/build/src/core/sequences.js +97 -0
- package/build/src/core/settings.d.ts +5 -0
- package/build/src/core/settings.js +31 -3
- package/build/src/core/template_language.d.ts +61 -0
- package/build/src/core/template_language.js +141 -0
- package/build/src/core/ui_preferences.d.ts +10 -0
- package/build/src/core/ui_preferences.js +15 -1
- package/build/src/core/user_avatars.d.ts +79 -0
- package/build/src/core/user_avatars.js +186 -0
- package/build/src/core/user_invitations.d.ts +5 -1
- package/build/src/core/user_invitations.js +7 -1
- package/build/src/core/user_preferences.d.ts +36 -0
- package/build/src/core/user_preferences.js +125 -0
- package/build/src/core/users.d.ts +2 -0
- package/build/src/core/users.js +5 -3
- package/build/src/database/calendar_days.d.ts +19 -0
- package/build/src/database/calendar_days.js +36 -0
- package/build/src/database/schema.d.ts +201 -2
- package/build/src/database/schema.js +713 -59
- package/build/src/database/schema_diff.d.ts +70 -0
- package/build/src/database/schema_diff.js +190 -0
- package/build/src/events/record_mutation.d.ts +2 -1
- package/build/src/events/record_mutation.js +1 -0
- package/build/src/integrations/api_client.d.ts +37 -0
- package/build/src/integrations/api_client.js +567 -0
- package/build/src/integrations/import_adapters.d.ts +37 -0
- package/build/src/integrations/import_adapters.js +35 -0
- package/build/src/integrations/imports.d.ts +130 -16
- package/build/src/integrations/imports.js +434 -73
- package/build/src/integrations/openapi.d.ts +3 -1
- package/build/src/integrations/openapi.js +465 -31
- package/build/src/integrations/outbound.d.ts +94 -0
- package/build/src/integrations/outbound.js +276 -0
- package/build/src/integrations/print.d.ts +22 -1
- package/build/src/integrations/print.js +68 -22
- package/build/src/integrations/print_templates.d.ts +216 -0
- package/build/src/integrations/print_templates.js +1017 -0
- package/build/src/integrations/sync_jobs.d.ts +139 -0
- package/build/src/integrations/sync_jobs.js +416 -0
- package/build/src/integrations/webhooks.d.ts +12 -12
- package/build/src/integrations/webhooks.js +34 -43
- package/build/src/integrations/xlsx.d.ts +41 -0
- package/build/src/integrations/xlsx.js +519 -0
- package/build/src/languages/ar.d.ts +11 -0
- package/build/src/languages/ar.js +358 -0
- package/build/src/languages/ar_ui.d.ts +461 -0
- package/build/src/languages/ar_ui.js +464 -0
- package/build/src/languages/catalog.d.ts +66 -0
- package/build/src/languages/catalog.js +152 -0
- package/build/src/languages/en.d.ts +7 -0
- package/build/src/languages/en.js +352 -0
- package/build/src/languages/en_ui.d.ts +3 -0
- package/build/src/languages/en_ui.js +458 -0
- package/build/src/languages/validation.d.ts +26 -0
- package/build/src/languages/validation.js +60 -0
- package/build/src/lists/bulk_actions.d.ts +89 -0
- package/build/src/lists/bulk_actions.js +268 -0
- package/build/src/lists/dashboards.d.ts +138 -0
- package/build/src/lists/dashboards.js +290 -0
- package/build/src/mcp/tools.js +9 -104
- package/build/src/resource/define_resource.d.ts +18 -1
- package/build/src/resource/define_resource.js +212 -18
- package/build/src/resource/definition.d.ts +44 -0
- package/build/src/resource/definition.js +171 -0
- package/build/src/resource/registry.js +15 -4
- package/build/src/resource/types.d.ts +313 -16
- package/build/src/resource/values.d.ts +56 -1
- package/build/src/resource/values.js +237 -5
- package/build/src/services/settings.d.ts +2 -0
- package/build/src/services/settings.js +5 -1
- package/build/src/upgrade/legacy.js +2 -2
- package/build/src/workflows/calendar.d.ts +9 -0
- package/build/src/workflows/calendar.js +44 -0
- package/build/src/workflows/define_workflow.d.ts +48 -3
- package/build/src/workflows/define_workflow.js +57 -13
- package/build/src/workflows/delegations.d.ts +107 -0
- package/build/src/workflows/delegations.js +326 -0
- package/build/src/workflows/engine.d.ts +80 -4
- package/build/src/workflows/engine.js +466 -86
- package/build/src/workflows/sla.d.ts +15 -0
- package/build/src/workflows/sla.js +8 -0
- package/build/stubs/resource_contract.txt +12 -1
- package/package.json +9 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
export default class BackupCreate extends BaseCommand {
|
|
3
|
+
static commandName: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static options: {
|
|
6
|
+
startApp: boolean;
|
|
7
|
+
};
|
|
8
|
+
snapshot: string;
|
|
9
|
+
prefix: string;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { resolve, join, basename } from 'node:path';
|
|
9
|
+
import { createReadStream } from 'node:fs';
|
|
10
|
+
import { stat, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { applicationEnv, backupSnapshotService } from './backup_services.js';
|
|
12
|
+
export default class BackupCreate extends BaseCommand {
|
|
13
|
+
static commandName = 'backup:create';
|
|
14
|
+
static description = 'Create a consistent database and all-disk attachment snapshot; publish COMPLETE last';
|
|
15
|
+
static options = { startApp: true };
|
|
16
|
+
async run() {
|
|
17
|
+
const env = await applicationEnv(this.app);
|
|
18
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
19
|
+
const { Settings } = await import('../src/services/settings.js');
|
|
20
|
+
const { createSnapshot } = await backupSnapshotService(this.app);
|
|
21
|
+
const { publishSnapshot } = (await this.app.import('#services/backup_publish'));
|
|
22
|
+
const directory = resolve(this.snapshot);
|
|
23
|
+
const bucket = env.get('BACKUP_S3_BUCKET');
|
|
24
|
+
const prefix = this.prefix ?? `${env.get('BACKUP_S3_PREFIX') ?? 'adula'}/${basename(directory)}/`;
|
|
25
|
+
if (!/^adula\/[a-zA-Z0-9/_-]+\/$/.test(prefix) || prefix.includes('//'))
|
|
26
|
+
throw new Error('Invalid offsite prefix');
|
|
27
|
+
const { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand } = bucket
|
|
28
|
+
? (await this.app.import('@aws-sdk/client-s3'))
|
|
29
|
+
: {};
|
|
30
|
+
const client = bucket
|
|
31
|
+
? new S3Client({
|
|
32
|
+
region: env.get('BACKUP_S3_REGION'),
|
|
33
|
+
endpoint: env.get('BACKUP_S3_ENDPOINT'),
|
|
34
|
+
credentials: {
|
|
35
|
+
accessKeyId: env.get('BACKUP_S3_ACCESS_KEY_ID'),
|
|
36
|
+
secretAccessKey: env.get('BACKUP_S3_SECRET_ACCESS_KEY'),
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
: null;
|
|
40
|
+
try {
|
|
41
|
+
if (client) {
|
|
42
|
+
try {
|
|
43
|
+
await client.send(new HeadObjectCommand({ Bucket: bucket, Key: prefix + 'COMPLETE' }));
|
|
44
|
+
throw new Error('Refusing to overwrite a complete offsite snapshot');
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.$metadata?.httpStatusCode !== 404)
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
await createSnapshot(directory);
|
|
52
|
+
if (client) {
|
|
53
|
+
await publishSnapshot(directory, {
|
|
54
|
+
exists: async () => {
|
|
55
|
+
try {
|
|
56
|
+
await client.send(new HeadObjectCommand({ Bucket: bucket, Key: prefix + 'COMPLETE' }));
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error.$metadata?.httpStatusCode ===
|
|
61
|
+
404)
|
|
62
|
+
return false;
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
put: async (name, path) => {
|
|
67
|
+
const info = path ? await stat(path) : null;
|
|
68
|
+
await client.send(new PutObjectCommand({
|
|
69
|
+
Bucket: bucket,
|
|
70
|
+
Key: prefix + name,
|
|
71
|
+
Body: path ? createReadStream(path) : '',
|
|
72
|
+
ContentLength: info?.size ?? 0,
|
|
73
|
+
}));
|
|
74
|
+
},
|
|
75
|
+
read: async (name) => {
|
|
76
|
+
const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: prefix + name }));
|
|
77
|
+
if (!response.Body)
|
|
78
|
+
throw new Error('Missing offsite body: ' + name);
|
|
79
|
+
return response.Body;
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
await new Settings(db.connection().getWriteClient()).set('backup.lastOffsite', new Date().toISOString());
|
|
83
|
+
}
|
|
84
|
+
await writeFile(join(directory, 'COMPLETE'), '');
|
|
85
|
+
this.logger.success(`Backup complete: ${directory}`);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
client?.destroy();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__decorate([
|
|
93
|
+
flags.string({ required: true, description: 'New snapshot directory (must not exist)' })
|
|
94
|
+
], BackupCreate.prototype, "snapshot", void 0);
|
|
95
|
+
__decorate([
|
|
96
|
+
flags.string({
|
|
97
|
+
description: 'Offsite key prefix (defaults to adula/<snapshot directory name>/)',
|
|
98
|
+
})
|
|
99
|
+
], BackupCreate.prototype, "prefix", void 0);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
/**
|
|
3
|
+
* Opens an encrypted `.adulabackup` file into a new snapshot directory for the existing
|
|
4
|
+
* restore commands (ADR 051). The directory holds plaintext data and must be deleted after
|
|
5
|
+
* the restore.
|
|
6
|
+
*/
|
|
7
|
+
export default class BackupOpen extends BaseCommand {
|
|
8
|
+
static commandName: string;
|
|
9
|
+
static description: string;
|
|
10
|
+
static options: {
|
|
11
|
+
startApp: boolean;
|
|
12
|
+
};
|
|
13
|
+
file: string;
|
|
14
|
+
snapshot: string;
|
|
15
|
+
run(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { rm } from 'node:fs/promises';
|
|
9
|
+
import { resolve } from 'node:path';
|
|
10
|
+
import { openBackupArchive, parseBackupKey } from '../src/backups/archive.js';
|
|
11
|
+
import { applicationEnv, backupSnapshotService } from './backup_services.js';
|
|
12
|
+
/**
|
|
13
|
+
* Opens an encrypted `.adulabackup` file into a new snapshot directory for the existing
|
|
14
|
+
* restore commands (ADR 051). The directory holds plaintext data and must be deleted after
|
|
15
|
+
* the restore.
|
|
16
|
+
*/
|
|
17
|
+
export default class BackupOpen extends BaseCommand {
|
|
18
|
+
static commandName = 'backup:open';
|
|
19
|
+
static description = 'Decrypt an .adulabackup file into a new snapshot directory for restore';
|
|
20
|
+
static options = { startApp: true };
|
|
21
|
+
async run() {
|
|
22
|
+
const env = await applicationEnv(this.app);
|
|
23
|
+
const value = env.get('BACKUP_ENCRYPTION_KEY');
|
|
24
|
+
if (!value) {
|
|
25
|
+
this.logger.error('BACKUP_ENCRYPTION_KEY is not set');
|
|
26
|
+
this.exitCode = 1;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const target = resolve(this.snapshot);
|
|
30
|
+
await openBackupArchive(resolve(this.file), target, parseBackupKey(value));
|
|
31
|
+
const { verifySnapshot } = await backupSnapshotService(this.app);
|
|
32
|
+
try {
|
|
33
|
+
await verifySnapshot(target);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
await rm(target, { recursive: true, force: true });
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
this.logger.success(`Snapshot opened in ${target}`);
|
|
40
|
+
this.logger.warning('This directory holds unencrypted data: delete it after backup:verify-snapshot and the restore');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__decorate([
|
|
44
|
+
flags.string({ required: true })
|
|
45
|
+
], BackupOpen.prototype, "file", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
flags.string({ required: true })
|
|
48
|
+
], BackupOpen.prototype, "snapshot", void 0);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
export default class BackupRestoreFiles extends BaseCommand {
|
|
3
|
+
static commandName: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static options: {
|
|
6
|
+
startApp: boolean;
|
|
7
|
+
};
|
|
8
|
+
snapshot: string;
|
|
9
|
+
apply: boolean;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join, resolve } from 'node:path';
|
|
11
|
+
import { backupSnapshotService } from './backup_services.js';
|
|
12
|
+
export default class BackupRestoreFiles extends BaseCommand {
|
|
13
|
+
static commandName = 'backup:restore-files';
|
|
14
|
+
static description = 'Restore verified attachment bytes to their original disks after database recovery';
|
|
15
|
+
static options = { startApp: true };
|
|
16
|
+
async run() {
|
|
17
|
+
if (!this.apply)
|
|
18
|
+
throw new Error('Use --apply after restoring the database with application traffic stopped');
|
|
19
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
20
|
+
const { verifySnapshot, extractSnapshot, verifyAttachments, restoreAttachments } = await backupSnapshotService(this.app);
|
|
21
|
+
const snapshot = resolve(this.snapshot);
|
|
22
|
+
const files = await verifySnapshot(snapshot);
|
|
23
|
+
if (!files)
|
|
24
|
+
throw new Error('Legacy snapshots must use the local-files restore script');
|
|
25
|
+
const extracted = await mkdtemp(join(tmpdir(), 'adula-recovery-'));
|
|
26
|
+
try {
|
|
27
|
+
await extractSnapshot(snapshot, extracted);
|
|
28
|
+
await verifyAttachments(files, extracted, await db.connection().getWriteClient()('attachments').select('*'));
|
|
29
|
+
await restoreAttachments(files, extracted, false);
|
|
30
|
+
this.logger.success(`Restored and verified ${files.length} attachments on their original disks`);
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
await rm(extracted, { recursive: true, force: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
__decorate([
|
|
38
|
+
flags.string({ required: true })
|
|
39
|
+
], BackupRestoreFiles.prototype, "snapshot", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
flags.boolean({
|
|
42
|
+
description: 'Write original attachment keys; stop application traffic before recovery',
|
|
43
|
+
})
|
|
44
|
+
], BackupRestoreFiles.prototype, "apply", void 0);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
export default class BackupRestoreTest extends BaseCommand {
|
|
3
|
+
static commandName: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static options: {
|
|
6
|
+
startApp: boolean;
|
|
7
|
+
};
|
|
8
|
+
dir: string;
|
|
9
|
+
snapshot: string;
|
|
10
|
+
allowEmpty: boolean;
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { execFile } from 'node:child_process';
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
10
|
+
import { mkdtemp, readdir, rm, stat } from 'node:fs/promises';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join, resolve } from 'node:path';
|
|
13
|
+
import { promisify } from 'node:util';
|
|
14
|
+
import { applicationEnv, backupSnapshotService } from './backup_services.js';
|
|
15
|
+
const run = promisify(execFile);
|
|
16
|
+
const SNAPSHOT = /^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}Z$/;
|
|
17
|
+
async function latestSnapshot(directory) {
|
|
18
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
19
|
+
const candidates = [];
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (!entry.isDirectory() || !SNAPSHOT.test(entry.name))
|
|
22
|
+
continue;
|
|
23
|
+
try {
|
|
24
|
+
await stat(join(directory, entry.name, 'COMPLETE'));
|
|
25
|
+
candidates.push(entry.name);
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
if (!candidates.length)
|
|
30
|
+
throw new Error(`No complete snapshot found under ${directory}`);
|
|
31
|
+
return join(directory, candidates.sort().at(-1));
|
|
32
|
+
}
|
|
33
|
+
export default class BackupRestoreTest extends BaseCommand {
|
|
34
|
+
static commandName = 'backup:restore-test';
|
|
35
|
+
static description = 'Restore the latest snapshot into a temporary database and verify a record together with its attachment file';
|
|
36
|
+
static options = { startApp: true };
|
|
37
|
+
async run() {
|
|
38
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
39
|
+
const env = await applicationEnv(this.app);
|
|
40
|
+
const { Settings } = await import('../src/services/settings.js');
|
|
41
|
+
const { isRelativeDiskPath } = await import('../src/attachments/attachment_service.js');
|
|
42
|
+
const { registry } = (await this.app.import('#start/modules'));
|
|
43
|
+
const { verifySnapshot, extractSnapshot, verifyAttachments, restoreAttachments } = await backupSnapshotService(this.app);
|
|
44
|
+
const live = db.connection().getWriteClient();
|
|
45
|
+
const settings = new Settings(live);
|
|
46
|
+
const startedAt = new Date();
|
|
47
|
+
const report = { startedAt: startedAt.toISOString(), status: 'failed' };
|
|
48
|
+
const stamp = startedAt
|
|
49
|
+
.toISOString()
|
|
50
|
+
.replace(/[-:]/g, '')
|
|
51
|
+
.replace(/\.\d+Z$/, '')
|
|
52
|
+
.toLowerCase();
|
|
53
|
+
const database = `${env.get('DB_DATABASE').slice(0, 20)}_restore_${stamp}_${randomUUID().slice(0, 8)}_test`;
|
|
54
|
+
const pgEnv = {
|
|
55
|
+
...process.env,
|
|
56
|
+
PGHOST: env.get('DB_HOST'),
|
|
57
|
+
PGPORT: String(env.get('DB_PORT')),
|
|
58
|
+
PGUSER: env.get('DB_USER'),
|
|
59
|
+
PGPASSWORD: env.get('DB_PASSWORD'),
|
|
60
|
+
};
|
|
61
|
+
let extracted;
|
|
62
|
+
let connected = false;
|
|
63
|
+
let created = false;
|
|
64
|
+
try {
|
|
65
|
+
const snapshot = this.snapshot
|
|
66
|
+
? resolve(this.snapshot)
|
|
67
|
+
: await latestSnapshot(resolve(this.dir ?? '/backups'));
|
|
68
|
+
report.snapshot = snapshot;
|
|
69
|
+
const files = await verifySnapshot(snapshot);
|
|
70
|
+
await live.raw('CREATE DATABASE ??', [database]);
|
|
71
|
+
created = true;
|
|
72
|
+
report.database = database;
|
|
73
|
+
await run('pg_restore', [
|
|
74
|
+
'--no-owner',
|
|
75
|
+
'--no-privileges',
|
|
76
|
+
'--exit-on-error',
|
|
77
|
+
`--dbname=${database}`,
|
|
78
|
+
join(snapshot, 'database.dump'),
|
|
79
|
+
], { env: pgEnv, windowsHide: true, timeout: 600000, maxBuffer: 16 * 1024 * 1024 });
|
|
80
|
+
extracted = await mkdtemp(join(tmpdir(), 'adula-restore-'));
|
|
81
|
+
await extractSnapshot(snapshot, extracted);
|
|
82
|
+
db.manager.add(database, {
|
|
83
|
+
client: 'pg',
|
|
84
|
+
connection: {
|
|
85
|
+
host: env.get('DB_HOST'),
|
|
86
|
+
port: env.get('DB_PORT'),
|
|
87
|
+
user: env.get('DB_USER'),
|
|
88
|
+
password: env.get('DB_PASSWORD'),
|
|
89
|
+
database,
|
|
90
|
+
},
|
|
91
|
+
pool: { min: 0, max: 2 },
|
|
92
|
+
});
|
|
93
|
+
connected = true;
|
|
94
|
+
const restored = db.connection(database).getWriteClient();
|
|
95
|
+
const tables = {};
|
|
96
|
+
for (const resource of registry.all()) {
|
|
97
|
+
const count = await restored(resource.name)
|
|
98
|
+
.whereNull('deleted_at')
|
|
99
|
+
.count('* as count')
|
|
100
|
+
.first();
|
|
101
|
+
tables[resource.name] = Number(count?.count ?? 0);
|
|
102
|
+
}
|
|
103
|
+
const attachments = await restored('attachments')
|
|
104
|
+
.whereNull('deleted_at')
|
|
105
|
+
.count('* as count')
|
|
106
|
+
.first();
|
|
107
|
+
tables.attachments = Number(attachments?.count ?? 0);
|
|
108
|
+
report.tables = tables;
|
|
109
|
+
if (files) {
|
|
110
|
+
await verifyAttachments(files, extracted, await restored('attachments').select('*'));
|
|
111
|
+
await restoreAttachments(files, extracted, true);
|
|
112
|
+
report.verifiedFiles = files.length;
|
|
113
|
+
}
|
|
114
|
+
else if (await restored('attachments').whereNot('disk', 'local').first()) {
|
|
115
|
+
throw new Error('Legacy snapshot does not contain non-local attachments');
|
|
116
|
+
}
|
|
117
|
+
// Only files of registered resources have a record the drill can open; profile
|
|
118
|
+
// pictures (ADR 050) and other owners are verified with every file above.
|
|
119
|
+
const candidate = await restored('attachments')
|
|
120
|
+
.whereNull('deleted_at')
|
|
121
|
+
.whereNotNull('record_id')
|
|
122
|
+
.whereIn('resource', registry.all().map((entry) => entry.name))
|
|
123
|
+
.orderBy('id', 'desc')
|
|
124
|
+
.first();
|
|
125
|
+
if (!candidate) {
|
|
126
|
+
if (!this.allowEmpty)
|
|
127
|
+
throw new Error('No record with an attachment exists in the snapshot; the drill cannot verify a file');
|
|
128
|
+
report.attachment = null;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const resource = registry.all().find((entry) => entry.name === candidate.resource);
|
|
132
|
+
if (!resource)
|
|
133
|
+
throw new Error(`Attachment ${candidate.id} belongs to unknown resource ${candidate.resource}`);
|
|
134
|
+
const record = await restored(resource.name)
|
|
135
|
+
.where('id', candidate.record_id)
|
|
136
|
+
.whereNull('deleted_at')
|
|
137
|
+
.first('id');
|
|
138
|
+
if (!record)
|
|
139
|
+
throw new Error(`Record ${candidate.resource}#${candidate.record_id} for attachment ${candidate.id} is missing from the restored database`);
|
|
140
|
+
if (!isRelativeDiskPath(candidate.path))
|
|
141
|
+
throw new Error(`Unsafe attachment path: ${candidate.path}`);
|
|
142
|
+
const file = await stat(join(extracted, files ? `${candidate.id}.bin` : candidate.path)).catch(() => undefined);
|
|
143
|
+
if (!file || !file.isFile())
|
|
144
|
+
throw new Error(`Attachment ${candidate.id} file ${candidate.path} is missing from uploads.tar.gz`);
|
|
145
|
+
if (file.size !== Number(candidate.size))
|
|
146
|
+
throw new Error(`Attachment ${candidate.id} file ${candidate.path} has ${file.size} bytes, expected ${candidate.size}`);
|
|
147
|
+
report.attachment = {
|
|
148
|
+
id: Number(candidate.id),
|
|
149
|
+
resource: String(candidate.resource),
|
|
150
|
+
recordId: Number(candidate.record_id),
|
|
151
|
+
field: String(candidate.field),
|
|
152
|
+
path: String(candidate.path),
|
|
153
|
+
size: Number(candidate.size),
|
|
154
|
+
fileVerified: true,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
report.status = 'passed';
|
|
158
|
+
report.finishedAt = new Date().toISOString();
|
|
159
|
+
await settings.set('backup.lastRestoreTest', report.finishedAt);
|
|
160
|
+
await settings.set('backup.lastRestoreTestReport', report);
|
|
161
|
+
this.logger.success(`Restore drill passed: ${JSON.stringify(report)}`);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
report.error = error instanceof Error ? error.message : String(error);
|
|
165
|
+
report.finishedAt = new Date().toISOString();
|
|
166
|
+
await settings.set('backup.lastRestoreTestReport', report);
|
|
167
|
+
this.logger.error(`Restore drill failed: ${JSON.stringify(report)}`);
|
|
168
|
+
this.exitCode = 1;
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
if (connected)
|
|
172
|
+
await db.manager.close(database, true);
|
|
173
|
+
if (created)
|
|
174
|
+
await live.raw('DROP DATABASE IF EXISTS ?? WITH (FORCE)', [database]);
|
|
175
|
+
if (extracted)
|
|
176
|
+
await rm(extracted, { recursive: true, force: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
__decorate([
|
|
181
|
+
flags.string({ description: 'Directory that holds dated snapshots (default: /backups)' })
|
|
182
|
+
], BackupRestoreTest.prototype, "dir", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
flags.string({ description: 'Explicit snapshot directory instead of the latest one' })
|
|
185
|
+
], BackupRestoreTest.prototype, "snapshot", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
flags.boolean({ description: 'Pass even when no record carries an attachment' })
|
|
188
|
+
], BackupRestoreTest.prototype, "allowEmpty", void 0);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
/** Seals a verified snapshot directory into an encrypted `.adulabackup` file (ADR 051). */
|
|
3
|
+
export default class BackupSeal extends BaseCommand {
|
|
4
|
+
static commandName: string;
|
|
5
|
+
static description: string;
|
|
6
|
+
static options: {
|
|
7
|
+
startApp: boolean;
|
|
8
|
+
};
|
|
9
|
+
snapshot: string;
|
|
10
|
+
file: string;
|
|
11
|
+
run(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { parseBackupKey, sealBackupArchive } from '../src/backups/archive.js';
|
|
10
|
+
import { applicationEnv, backupSnapshotService } from './backup_services.js';
|
|
11
|
+
/** Seals a verified snapshot directory into an encrypted `.adulabackup` file (ADR 051). */
|
|
12
|
+
export default class BackupSeal extends BaseCommand {
|
|
13
|
+
static commandName = 'backup:seal';
|
|
14
|
+
static description = 'Encrypt a verified snapshot directory into a new .adulabackup file';
|
|
15
|
+
static options = { startApp: true };
|
|
16
|
+
async run() {
|
|
17
|
+
const env = await applicationEnv(this.app);
|
|
18
|
+
const value = env.get('BACKUP_ENCRYPTION_KEY');
|
|
19
|
+
if (!value) {
|
|
20
|
+
this.logger.error('BACKUP_ENCRYPTION_KEY is not set');
|
|
21
|
+
this.exitCode = 1;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const directory = resolve(this.snapshot);
|
|
25
|
+
const { verifySnapshot } = await backupSnapshotService(this.app);
|
|
26
|
+
await verifySnapshot(directory);
|
|
27
|
+
const { size, sha256 } = await sealBackupArchive(directory, resolve(this.file), parseBackupKey(value));
|
|
28
|
+
this.logger.success(`Sealed ${size} bytes, sha256 ${sha256}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
__decorate([
|
|
32
|
+
flags.string({ required: true })
|
|
33
|
+
], BackupSeal.prototype, "snapshot", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
flags.string({ required: true })
|
|
36
|
+
], BackupSeal.prototype, "file", void 0);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ApplicationService } from '@adonisjs/core/types';
|
|
2
|
+
/**
|
|
3
|
+
* The backup commands ship with the package, while the snapshot format, the Drive disks and
|
|
4
|
+
* the validated environment belong to the application. They are resolved through the
|
|
5
|
+
* application's importer, so `#start/env` and `#services/backup_*` are the application's own.
|
|
6
|
+
*/
|
|
7
|
+
export type ArchivedAttachment = {
|
|
8
|
+
id: number;
|
|
9
|
+
disk: string;
|
|
10
|
+
path: string;
|
|
11
|
+
size: number;
|
|
12
|
+
sha256: string;
|
|
13
|
+
};
|
|
14
|
+
export type BackupSnapshotService = {
|
|
15
|
+
createSnapshot(directory: string, options?: {
|
|
16
|
+
workDirectory?: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
verifySnapshot(directory: string): Promise<ArchivedAttachment[] | null>;
|
|
19
|
+
extractSnapshot(directory: string, target: string): Promise<void>;
|
|
20
|
+
verifyAttachments(files: ArchivedAttachment[], extracted: string, rows: Record<string, any>[]): Promise<void>;
|
|
21
|
+
restoreAttachments(files: ArchivedAttachment[], extracted: string, drill: boolean): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export type SnapshotTransport = {
|
|
24
|
+
exists(): Promise<boolean>;
|
|
25
|
+
put(name: string, file?: string): Promise<void>;
|
|
26
|
+
read(name: string): Promise<AsyncIterable<Uint8Array>>;
|
|
27
|
+
};
|
|
28
|
+
/** The application's validated environment (`#start/env`). */
|
|
29
|
+
export type ApplicationEnv = {
|
|
30
|
+
get(key: string): any;
|
|
31
|
+
};
|
|
32
|
+
export declare function applicationEnv(app: ApplicationService): Promise<ApplicationEnv>;
|
|
33
|
+
export declare function backupSnapshotService(app: ApplicationService): Promise<BackupSnapshotService>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { applicationEnv } from './backup_services.js';
|
|
5
|
+
export default class BackupVerify extends BaseCommand {
|
|
6
|
+
static commandName = 'backup:verify';
|
|
7
|
+
static description = 'Verify recent database, uploads and checksum objects in offsite storage';
|
|
8
|
+
static options = { startApp: true };
|
|
9
|
+
async run() {
|
|
10
|
+
const { verifyBackup } = await import('../src/services/backup.js');
|
|
11
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
12
|
+
const env = await applicationEnv(this.app);
|
|
13
|
+
const prefix = env.get('BACKUP_S3_PREFIX') ?? 'adula';
|
|
14
|
+
const status = await verifyBackup(db.connection().getWriteClient(), async () => {
|
|
15
|
+
const endpoint = env.get('BACKUP_S3_ENDPOINT');
|
|
16
|
+
const bucket = env.get('BACKUP_S3_BUCKET');
|
|
17
|
+
if (!endpoint || !bucket)
|
|
18
|
+
throw new Error('Offsite storage is not configured');
|
|
19
|
+
const { stdout } = await promisify(execFile)('aws', [
|
|
20
|
+
'--endpoint-url',
|
|
21
|
+
endpoint,
|
|
22
|
+
's3api',
|
|
23
|
+
'list-objects-v2',
|
|
24
|
+
'--bucket',
|
|
25
|
+
bucket,
|
|
26
|
+
'--prefix',
|
|
27
|
+
prefix + '/',
|
|
28
|
+
'--output',
|
|
29
|
+
'json',
|
|
30
|
+
], {
|
|
31
|
+
timeout: 60000,
|
|
32
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
33
|
+
windowsHide: true,
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
AWS_ACCESS_KEY_ID: env.get('BACKUP_S3_ACCESS_KEY_ID'),
|
|
37
|
+
AWS_SECRET_ACCESS_KEY: env.get('BACKUP_S3_SECRET_ACCESS_KEY'),
|
|
38
|
+
AWS_DEFAULT_REGION: env.get('BACKUP_S3_REGION'),
|
|
39
|
+
AWS_PAGER: '',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const result = JSON.parse(stdout);
|
|
43
|
+
return (result.Contents ?? []).map((item) => ({
|
|
44
|
+
key: item.Key,
|
|
45
|
+
size: item.Size,
|
|
46
|
+
modifiedAt: item.LastModified,
|
|
47
|
+
}));
|
|
48
|
+
}, Date.now(), prefix);
|
|
49
|
+
const { Settings } = await import('../src/services/settings.js');
|
|
50
|
+
const { backupFingerprint } = (await this.app.import('#services/initial_setup'));
|
|
51
|
+
await new Settings(db.connection().getWriteClient()).set('setup.backup_check', {
|
|
52
|
+
fingerprint: backupFingerprint(),
|
|
53
|
+
at: status.checkedAt,
|
|
54
|
+
});
|
|
55
|
+
this.logger.log(JSON.stringify(status));
|
|
56
|
+
if (!status.healthy)
|
|
57
|
+
this.exitCode = 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
export default class BackupVerifySnapshot extends BaseCommand {
|
|
3
|
+
static commandName: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
static options: {
|
|
6
|
+
startApp: boolean;
|
|
7
|
+
};
|
|
8
|
+
snapshot: string;
|
|
9
|
+
run(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import { join, resolve } from 'node:path';
|
|
11
|
+
import { applicationEnv, backupSnapshotService } from './backup_services.js';
|
|
12
|
+
export default class BackupVerifySnapshot extends BaseCommand {
|
|
13
|
+
static commandName = 'backup:verify-snapshot';
|
|
14
|
+
static description = 'Validate snapshot checksums, manifest and archive before database recovery';
|
|
15
|
+
static options = { startApp: true };
|
|
16
|
+
async run() {
|
|
17
|
+
const { verifySnapshot, extractSnapshot, verifyAttachments } = await backupSnapshotService(this.app);
|
|
18
|
+
const env = await applicationEnv(this.app);
|
|
19
|
+
const directory = resolve(this.snapshot);
|
|
20
|
+
const files = await verifySnapshot(directory);
|
|
21
|
+
if (!files && env.get('DRIVE_DISK') !== 'local')
|
|
22
|
+
throw new Error('Legacy snapshot does not contain S3 attachments');
|
|
23
|
+
const extracted = await mkdtemp(join(tmpdir(), 'adula-verify-'));
|
|
24
|
+
try {
|
|
25
|
+
await extractSnapshot(directory, extracted);
|
|
26
|
+
if (files)
|
|
27
|
+
await verifyAttachments(files, extracted, files);
|
|
28
|
+
this.logger.success('Snapshot integrity verified');
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await rm(extracted, { recursive: true, force: true });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
__decorate([
|
|
36
|
+
flags.string({ required: true })
|
|
37
|
+
], BackupVerifySnapshot.prototype, "snapshot", void 0);
|