Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

feat: adds the ability to repair repo issues from ui for some cases

towfiqi8fa84e51b96b
diff --git a/backend/__tests__/controllers/PlanController.test.ts b/backend/__tests__/controllers/PlanController.test.ts
index fbebf7c..60d5206 100644
--- a/backend/__tests__/controllers/PlanController.test.ts
+++ b/backend/__tests__/controllers/PlanController.test.ts
@@ -299,11 +299,11 @@ describe('PlanController', () => {
it('should successfully initiate backup', async () => {
mockRequest.params = { id: 'plan-1' };
- mockPlanService.performBackup.mockResolvedValue(undefined);
+ mockPlanService.performBackup.mockResolvedValue('');
await planController.performBackup(mockRequest as Request, mockResponse as Response);
- expect(mockPlanService.performBackup).toHaveBeenCalledWith('plan-1');
+ expect(mockPlanService.performBackup).toHaveBeenCalledWith('plan-1', undefined);
expect(mockStatus).toHaveBeenCalledWith(200);
expect(mockJson).toHaveBeenCalledWith({
success: true,
@@ -482,4 +482,50 @@ describe('PlanController', () => {
});
});
});
+
+ describe('repairRepo', () => {
+ it('should return 400 if plan ID is missing', async () => {
+ mockRequest.params = {};
+ mockRequest.query = { type: 'index' };
+
+ await planController.repairRepo(mockRequest as Request, mockResponse as Response);
+
+ expect(mockStatus).toHaveBeenCalledWith(400);
+ expect(mockJson).toHaveBeenCalledWith({
+ success: false,
+ error: 'Plan ID is required',
+ });
+ });
+
+ it('should return 400 if repair type is missing', async () => {
+ mockRequest.params = { id: 'plan-1' };
+ mockRequest.query = {};
+
+ await planController.repairRepo(mockRequest as Request, mockResponse as Response);
+
+ expect(mockStatus).toHaveBeenCalledWith(400);
+ expect(mockJson).toHaveBeenCalledWith({
+ success: false,
+ error: 'Type is required',
+ });
+ });
+
+ it('should return 200 when repair succeeds', async () => {
+ mockRequest.params = { id: 'plan-1' };
+ mockRequest.query = { type: 'index', replicationId: 'replica-1' };
+ mockPlanService.repairRepo.mockResolvedValue({
+ success: true,
+ result: { primary: 'repair completed' },
+ });
+
+ await planController.repairRepo(mockRequest as Request, mockResponse as Response);
+
+ expect(mockPlanService.repairRepo).toHaveBeenCalledWith('plan-1', 'index', 'replica-1');
+ expect(mockStatus).toHaveBeenCalledWith(200);
+ expect(mockJson).toHaveBeenCalledWith({
+ success: true,
+ result: { primary: 'repair completed' },
+ });
+ });
+ });
});
diff --git a/backend/__tests__/jobs/tasks/BackupTask.test.ts b/backend/__tests__/jobs/tasks/BackupTask.test.ts
index 167ea6a..eed0d6d 100644
--- a/backend/__tests__/jobs/tasks/BackupTask.test.ts
+++ b/backend/__tests__/jobs/tasks/BackupTask.test.ts
@@ -101,7 +101,8 @@ describe('BackupTask', () => {
{
attempts: 1,
maxAttempts: 5,
- }
+ },
+ undefined
);
expect(mockPlanLogger).toHaveBeenCalledWith('backup', 'plan-123', 'backup-456');
@@ -151,7 +152,8 @@ describe('BackupTask', () => {
{
attempts: 3,
maxAttempts: 10,
- }
+ },
+ undefined
);
});
@@ -173,7 +175,8 @@ describe('BackupTask', () => {
expect(mockBackupManagerPerformBackupExecution).toHaveBeenCalledWith(
'plan-123',
undefined,
- expect.any(Object)
+ expect.any(Object),
+ undefined
);
});
diff --git a/backend/__tests__/managers/BaseBackupManager.test.ts b/backend/__tests__/managers/BaseBackupManager.test.ts
index 5550d52..6437f16 100644
--- a/backend/__tests__/managers/BaseBackupManager.test.ts
+++ b/backend/__tests__/managers/BaseBackupManager.test.ts
@@ -366,10 +366,16 @@ describe('BaseBackupManager', () => {
maxAttempts: 5,
});
expect(backupHandlerExecuteMock).toHaveBeenCalledTimes(1);
- expect(backupHandlerExecuteMock).toHaveBeenCalledWith('plan-1', 'backup-1', baseOptions, {
- attempts: 1,
- maxAttempts: 5,
- });
+ expect(backupHandlerExecuteMock).toHaveBeenCalledWith(
+ 'plan-1',
+ 'backup-1',
+ baseOptions,
+ {
+ attempts: 1,
+ maxAttempts: 5,
+ },
+ undefined
+ );
expect(out).toBe('EXECUTED');
});
diff --git a/backend/__tests__/managers/handlers/BackupHandler.test.ts b/backend/__tests__/managers/handlers/BackupHandler.test.ts
index 6e598a1..6ef7a81 100644
--- a/backend/__tests__/managers/handlers/BackupHandler.test.ts
+++ b/backend/__tests__/managers/handlers/BackupHandler.test.ts
@@ -74,31 +74,129 @@ import { EventEmitter } from 'events';
import { BackupHandler } from '../../../src/managers/handlers/BackupHandler';
import os from 'os';
import fs from 'fs';
+import { BackupPlanArgs } from '#core-backend/types/plans';
describe('BackupHandler', () => {
let handler: BackupHandler;
let emitter: EventEmitter;
- const baseOptions = {
+ const baseOptions: BackupPlanArgs = {
id: 'plan-1',
title: 'Test Plan',
method: 'backup',
- storage: { name: 'test-storage', type: 'rclone' },
+ storage: {
+ name: 'test-storage',
+ type: 'rclone',
+ settings: {},
+ credentials: {},
+ authType: '',
+ defaultPath: '/',
+ },
storagePath: 'backups/test',
settings: {
- encryption: false,
+ interval: { type: 'daily', time: '10:00AM', days: '', hours: '', minutes: 5 },
compression: true,
+ encryption: true,
+ retries: 5,
+ retryDelay: 300, // in seconds
+ notification: {
+ email: {
+ enabled: false,
+ case: 'failure',
+ type: 'smtp',
+ emails: '',
+ },
+ webhook: {
+ enabled: false,
+ case: 'failure',
+ method: 'POST',
+ contentType: 'application/json',
+ url: '',
+ },
+ push: {
+ enabled: false,
+ url: '',
+ case: 'failure',
+ authType: 'none',
+ authToken: '',
+ tags: '',
+ },
+ slack: {
+ enabled: false,
+ case: 'failure',
+ url: '',
+ },
+ discord: {
+ enabled: false,
+ case: 'failure',
+ url: '',
+ },
+ },
+ prune: {
+ snapCount: 5,
+ policy: 'forgetByAge',
+ forgetAge: '1m',
+ revisions: false,
+ },
performance: {
+ scan: true,
maxProcessor: 2,
packSize: '16MiB',
},
+ integrity: {
+ enabled: false,
+ interval: { type: 'weekly', time: '10:00AM', days: 'sun', hours: '', minutes: 5 },
+ method: 'no-read',
+ notification: {
+ email: {
+ enabled: false,
+ type: 'smtp',
+ emails: '',
+ case: 'failure',
+ },
+ webhook: {
+ enabled: false,
+ method: 'POST',
+ contentType: 'application/json',
+ url: '',
+ case: 'failure',
+ },
+ push: {
+ enabled: false,
+ url: '',
+ authType: 'none',
+ authToken: '',
+ tags: '',
+ case: 'failure',
+ },
+ slack: {
+ enabled: false,
+ case: 'failure',
+ url: '',
+ },
+ discord: {
+ enabled: false,
+ case: 'failure',
+ url: '',
+ },
+ },
+ },
+ scripts: {
+ onBackupStart: [],
+ onBackupEnd: [],
+ onBackupError: [],
+ onBackupFailure: [],
+ onBackupComplete: [],
+ },
},
sourceConfig: {
includes: ['C:\\data'],
excludes: ['C:\\temp'],
},
- resticArgs: ['backup', 'C:\\data', '-r', 'test-repo'],
- resticEnv: { GOMAXPROCS: '2' },
+ sourceId: 'main',
+ cronExpression: '',
+ // resticArgs: ['backup', 'C:\\data', '-r', 'test-repo'],
+ // resticEnv: { GOMAXPROCS: '2' },
};
beforeEach(() => {
@@ -302,8 +400,8 @@ describe('BackupHandler', () => {
// Env variables for performance
expect(resticEnv.GOMAXPROCS).toBe('2');
- // No encryption => insecure flag
- expect(resticArgs).toContain('--insecure-no-password');
+ // Encryption is enabled in baseOptions => no insecure flag
+ expect(resticArgs).not.toContain('--insecure-no-password');
// Tag and json
expect(resticArgs).toContain('--tag');
@@ -688,7 +786,7 @@ describe('BackupHandler', () => {
expect(mockRunResticCommand).toHaveBeenCalledWith(
expect.arrayContaining(['--tag', 'backup-backup-1']),
- expect.objectContaining({ RESTIC_PASSWORD: '' }),
+ expect.objectContaining({ RESTIC_PASSWORD: 'test-encryption-key' }),
expect.any(Function),
expect.any(Function),
expect.any(Function),
@@ -853,7 +951,7 @@ describe('BackupHandler', () => {
'pre-backup',
'PRE_BACKUP_DRY_RUN_ERROR',
false,
- 'Dry run failed: Dry run error'
+ 'Dry run error'
);
});
@@ -880,7 +978,7 @@ describe('BackupHandler', () => {
expect(mockRunResticCommand).toHaveBeenCalledWith(
['unlock', '-r', 'rclone:test-storage:backups/test'],
- expect.objectContaining({ RESTIC_PASSWORD: '' })
+ expect.objectContaining({ RESTIC_PASSWORD: 'test-encryption-key' })
);
});
diff --git a/backend/__tests__/routes/plans.test.ts b/backend/__tests__/routes/plans.test.ts
index ea4a0cd..a1b5ab0 100644
--- a/backend/__tests__/routes/plans.test.ts
+++ b/backend/__tests__/routes/plans.test.ts
@@ -61,6 +61,7 @@ describe('Plan Routes', () => {
pruneBackups: jest.fn(),
unlockRepo: jest.fn(),
checkIntegrity: jest.fn(),
+ repairRepo: jest.fn(),
deleteReplicationStorage: jest.fn(),
} as any;
@@ -248,7 +249,19 @@ describe('Plan Routes', () => {
const response = await request(app).post('/api/plans/plan-1/action/backup');
expect(response.status).toBe(200);
- expect(mockPlanService.performBackup).toHaveBeenCalledWith('plan-1');
+ expect(mockPlanService.performBackup).toHaveBeenCalledWith('plan-1', undefined);
+ });
+
+ it('should forward runConfig when provided', async () => {
+ mockPlanService.performBackup.mockResolvedValue({ success: true } as any);
+ const runConfig = { forceFull: true };
+
+ const response = await request(app)
+ .post('/api/plans/plan-1/action/backup')
+ .send({ runConfig });
+
+ expect(response.status).toBe(200);
+ expect(mockPlanService.performBackup).toHaveBeenCalledWith('plan-1', runConfig);
});
});
@@ -328,4 +341,33 @@ describe('Plan Routes', () => {
expect(response.status).toBe(500);
});
});
+
+ describe('POST /api/plans/:id/action/repair', () => {
+ it('should return 401 if not authenticated', async () => {
+ setupAuthMock(false);
+
+ const response = await request(app).post('/api/plans/plan-1/action/repair?type=index');
+
+ expect(response.status).toBe(401);
+ });
+
+ it('should return 400 when repair type is missing', async () => {
+ const response = await request(app).post('/api/plans/plan-1/action/repair');
+
+ expect(response.status).toBe(400);
+ expect(mockPlanService.repairRepo).not.toHaveBeenCalled();
+ });
+
+ it('should repair repository for a plan when authenticated', async () => {
+ mockPlanService.repairRepo.mockResolvedValue({
+ success: true,
+ result: { primary: 'repair completed' },
+ } as any);
+
+ const response = await request(app).post('/api/plans/plan-1/action/repair?type=index');
+
+ expect(response.status).toBe(200);
+ expect(mockPlanService.repairRepo).toHaveBeenCalledWith('plan-1', 'index', undefined);
+ });
+ });
});
diff --git a/backend/__tests__/services/PlanService.test.ts b/backend/__tests__/services/PlanService.test.ts
index 06e4cc9..71a4957 100644
--- a/backend/__tests__/services/PlanService.test.ts
+++ b/backend/__tests__/services/PlanService.test.ts
@@ -551,7 +551,7 @@ describe('PlanService', () => {
// Assert
expect(mockPlanStore.getById).toHaveBeenCalledWith(planId);
expect(mockPlanStore.hasActiveBackups).toHaveBeenCalledWith(planId);
- expect(mockStrategy.performBackup).toHaveBeenCalledWith(planId);
+ expect(mockStrategy.performBackup).toHaveBeenCalledWith(planId, undefined);
});
it('should throw a NotFoundError if the plan does not exist', async () => {
@@ -910,6 +910,80 @@ describe('PlanService', () => {
});
});
+ describe('repairRepo', () => {
+ const planId = 'plan-to-repair';
+ const primaryIntegrityResult = { logs: ['restic repair index'] } as any;
+ const mirrorIntegrityResult = { logs: ['restic repair packs abc123'] } as any;
+ const mockPlan = {
+ id: planId,
+ sourceId: 'main',
+ storagePath: '/backups/primary',
+ storage: { name: 'Primary Storage' },
+ settings: {
+ replication: {
+ storages: [
+ {
+ replicationId: 'replica-1',
+ storageId: 'storage-2',
+ storageName: 'Replica Storage',
+ storagePath: '/backups/replica',
+ },
+ ],
+ },
+ },
+ verified: {
+ result: {
+ 'primary': primaryIntegrityResult,
+ 'mirror_storage-2': mirrorIntegrityResult,
+ },
+ },
+ } as any;
+
+ it('should successfully call repairRepo on the strategy for primary storage', async () => {
+ mockPlanStore.getById.mockResolvedValue(mockPlan);
+ mockStrategy.repairRepo = jest.fn().mockResolvedValue({
+ success: true,
+ result: { primary: 'repair completed' },
+ });
+
+ const result = await planService.repairRepo(planId, 'index');
+
+ expect(mockPlanStore.getById).toHaveBeenCalledWith(planId);
+ expect(mockStrategy.repairRepo).toHaveBeenCalledWith(
+ planId,
+ 'index',
+ primaryIntegrityResult,
+ {
+ storageName: 'Primary Storage',
+ storagePath: '/backups/primary',
+ }
+ );
+ expect(result).toEqual({
+ success: true,
+ result: { primary: 'repair completed' },
+ });
+ });
+
+ it('should successfully call repairRepo on the strategy for a replication storage', async () => {
+ mockPlanStore.getById.mockResolvedValue(mockPlan);
+ mockStrategy.repairRepo = jest.fn().mockResolvedValue({
+ success: true,
+ result: { primary: 'replica repair completed' },
+ });
+
+ const result = await planService.repairRepo(planId, 'packs', 'replica-1');
+
+ expect(mockStrategy.repairRepo).toHaveBeenCalledWith(planId, 'packs', mirrorIntegrityResult, {
+ storageName: 'Replica Storage',
+ storagePath: '/backups/replica',
+ });
+ expect(result).toEqual({
+ success: true,
+ result: { primary: 'replica repair completed' },
+ });
+ });
+ });
+
// -------------------------------------------------
// Tests for reconciling schedules with the database
// -------------------------------------------------
diff --git a/backend/__tests__/utils/restic/restic.test.ts b/backend/__tests__/utils/restic/restic.test.ts
index f7ec72b..d06466d 100644
--- a/backend/__tests__/utils/restic/restic.test.ts
+++ b/backend/__tests__/utils/restic/restic.test.ts
@@ -25,6 +25,7 @@ import {
runResticCommand,
getBackupPlanStats,
getSnapshotByTag,
+ handleResticCheckResult,
} from '../../../src/utils/restic/restic';
import { getBinaryPath } from '../../../src/utils/binaryPathResolver';
import { getRcloneConfigPath } from '../../../src/utils/rclone/helpers';
@@ -939,3 +940,300 @@ describe('getSnapshotByTag', () => {
expect(mockGenerateResticRepoPath).toHaveBeenCalledWith('custom-storage', 'custom-path');
});
});
+
+describe('handleResticCheckResult', () => {
+ const testContext = {
+ repo: '/path/to/repo',
+ device: 'test-device-001',
+ };
+
+ describe('successful checks', () => {
+ it('should handle check with no errors', () => {
+ const output = `{
+ "message_type": "summary",
+ "num_errors": 0,
+ "broken_packs": null,
+ "suggest_repair_index": false,
+ "suggest_prune": false
+}
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('No Issue Detected.');
+ expect(result.hasError).toBe(false);
+ expect(result.fix).toBe('');
+ expect(result.logs).toBeInstanceOf(Array);
+ expect(result.logs.length).toBeGreaterThan(0);
+ });
+
+ it('should handle check with verbose success output', () => {
+ const output = `Loading index
+Checking packs
+Checking snapshots
+Checking data blobs
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('No Issue Detected.');
+ expect(result.hasError).toBe(false);
+ expect(result.fix).toBe('');
+ });
+ });
+
+ describe('damaged repository index', () => {
+ it('should detect damaged index and provide fix', () => {
+ const output = `Loading index
+The repository index is damaged
+error: index file corrupted`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('The repository index is damaged.');
+ expect(result.hasError).toBe(true);
+ expect(result.fix).toContain('restic repair index');
+ expect(result.fix).toContain(testContext.repo);
+ expect(result.fix).toContain(testContext.device);
+ expect(result.fix).toContain('Pluton Encryption key');
+ });
+
+ it('should provide proper repair command for damaged index', () => {
+ const output = `The repository index is damaged
+Cannot read index file
+error: check failed`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('The repository index is damaged.');
+ expect(result.fix).toContain(`restic repair index -r ${testContext.repo}`);
+ });
+ });
+
+ describe('ciphertext verification failures', () => {
+ it('should detect ciphertext verification failure', () => {
+ const output = `Loading pack 1234567890abcdef
+ciphertext verification failed
+error: decryption error`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Ciphertext verification failed.');
+ expect(result.hasError).toBe(true);
+ expect(result.fix).toContain('hard to fix');
+ expect(result.fix).toContain('hardware problems');
+ expect(result.fix).toContain('Restic forum');
+ });
+
+ it('should provide appropriate guidance for ciphertext issues', () => {
+ const output = `ciphertext verification failed for blob
+error: authentication failed`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Ciphertext verification failed.');
+ expect(result.fix).toContain('IRC channel');
+ expect(result.fix).not.toContain('restic repair');
+ });
+ });
+
+ describe('authorization failures', () => {
+ it('should detect failed authorization', () => {
+ const output = `Connecting to repository
+failed to authorize account
+error: access denied`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Storage Authorization failed.');
+ expect(result.hasError).toBe(false);
+ expect(result.fix).toBe('');
+ });
+
+ it('should handle authorization failure without treating as error', () => {
+ const output = `failed to authorize account: invalid credentials
+Cannot access repository`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Storage Authorization failed.');
+ expect(result.hasError).toBe(false);
+ });
+ });
+
+ describe('logs processing', () => {
+ it('should filter out empty lines from logs', () => {
+ const output = `Line 1
+
+Line 2
+
+Line 3`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.logs).toEqual(['Line 1', 'Line 2', 'Line 3']);
+ expect(result.logs.length).toBe(3);
+ });
+
+ it('should trim whitespace and filter empty lines', () => {
+ const output = ` Line 1
+
+Line 2
+
+ Line 3 `;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.logs.length).toBe(3);
+ expect(result.logs).not.toContain('');
+ });
+
+ it('should include all non-empty lines in logs', () => {
+ const output = `Loading index
+Checking packs
+Checking snapshots
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.logs).toContain('Loading index');
+ expect(result.logs).toContain('Checking packs');
+ expect(result.logs).toContain('Checking snapshots');
+ expect(result.logs).toContain('no errors were found');
+ });
+ });
+
+ describe('multiple issues', () => {
+ it('should handle multiple error conditions where last one sets the message', () => {
+ const output = `The repository contains damaged pack files
+pack 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef: error
+The repository index is damaged
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ // All conditions are checked and message gets set multiple times
+ // Last condition "no errors were found" sets message and hasError
+ expect(result.message).toBe('No Issue Detected.');
+ expect(result.hasError).toBe(false);
+ });
+
+ it('should handle damaged pack file without success message', () => {
+ const output = `The repository contains damaged pack files
+pack 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef: error
+The repository index is damaged`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ // Both conditions are true, but index message comes last
+ expect(result.message).toBe('The repository index is damaged.');
+ expect(result.hasError).toBe(true);
+ });
+
+ it('should handle multiple error conditions and last success message', () => {
+ const output = `ciphertext verification failed
+failed to authorize account
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ // All three conditions are true, last one wins for message
+ expect(result.message).toBe('No Issue Detected.');
+ // But authorization failure sets hasError to false
+ expect(result.hasError).toBe(false);
+ });
+ });
+
+ describe('edge cases', () => {
+ it('should handle empty output', () => {
+ const output = '';
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('');
+ expect(result.hasError).toBe(true);
+ expect(result.fix).toBe('');
+ expect(result.logs).toEqual([]);
+ });
+
+ it('should handle output with only whitespace', () => {
+ const output = ' \n\n \n ';
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('');
+ expect(result.logs).toEqual([]);
+ });
+
+ it('should handle unknown error format', () => {
+ const output = `Some unknown error occurred
+Check failed for unknown reason`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('');
+ expect(result.hasError).toBe(true);
+ expect(result.logs.length).toBe(2);
+ });
+ });
+
+ describe('repository context', () => {
+ it('should use provided repository path in fix commands', () => {
+ const customContext = {
+ repo: '/custom/repo/path',
+ device: 'my-device',
+ };
+ const output = `The repository index is damaged`;
+
+ const result = handleResticCheckResult(output, customContext);
+
+ expect(result.fix).toContain('/custom/repo/path');
+ expect(result.fix).toContain('my-device');
+ });
+ });
+
+ describe('real-world scenarios', () => {
+ it('should handle typical successful check output', () => {
+ const output = `using temporary cache in /tmp/restic-check-cache-123456
+repository 1a2b3c4d opened (version 2, compression level auto)
+created new cache in /tmp/restic-check-cache-123456
+create exclusive lock for repository
+load indexes
+check all packs
+check snapshots, trees and blobs
+[0:00] 100.00% 3 / 3 snapshots
+no errors were found`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('No Issue Detected.');
+ expect(result.hasError).toBe(false);
+ expect(result.fix).toBe('');
+ expect(result.logs.length).toBeGreaterThan(5);
+ });
+
+ it('should handle corrupted repository scenario', () => {
+ const output = `using temporary cache in /tmp/restic-check-cache-123456
+repository 1a2b3c4d opened (version 2, compression level auto)
+Load(<data/1234567890abcd>, 0, 0) returned error, retrying after 552.330144ms: ciphertext verification failed
+Load(<data/1234567890abcd>, 0, 0) returned error, retrying after 552.330144ms: ciphertext verification failed
+ciphertext verification failed
+Fatal: repository contains errors`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Ciphertext verification failed.');
+ expect(result.hasError).toBe(true);
+ expect(result.fix).toContain('hardware problems');
+ });
+
+ it('should handle authentication error scenario', () => {
+ const output = `Fatal: create repository at s3:s3.amazonaws.com/backup failed: failed to authorize account: Forbidden`;
+
+ const result = handleResticCheckResult(output, testContext);
+
+ expect(result.message).toBe('Storage Authorization failed.');
+ expect(result.hasError).toBe(false);
+ });
+ });
+});
diff --git a/backend/src/controllers/PlanController.ts b/backend/src/controllers/PlanController.ts
index 7694c4a..9890ce6 100644
--- a/backend/src/controllers/PlanController.ts
+++ b/backend/src/controllers/PlanController.ts
@@ -1,5 +1,6 @@
import { Request, Response } from 'express';
import { NewPlanReq } from '../types/plans';
+import { BackupRunConfig } from '../types/backups';
import { PlanService } from '../services/PlanService';
import { AppError } from '../utils/AppError';
@@ -164,7 +165,8 @@ export class PlanController {
return;
}
- const result = await this.planService.performBackup(req.params.id);
+ const runConfig = (req.body as { runConfig?: BackupRunConfig } | undefined)?.runConfig;
+ const result = await this.planService.performBackup(req.params.id, runConfig);
res.status(200).json({ success: true, message: result || 'Backup initiated successfully' });
} catch (error: unknown) {
const appError = error as AppError;
@@ -365,6 +367,36 @@ export class PlanController {
}
}
+ async repairRepo(req: Request, res: Response): Promise<void> {
+ if (!req.params.id) {
+ res.status(400).json({
+ success: false,
+ error: 'Plan ID is required',
+ });
+ return;
+ }
+ if (!req.query.type) {
+ res.status(400).json({
+ success: false,
+ error: 'Type is required',
+ });
+ return;
+ }
+ try {
+ const repairType = req.query.type as string;
+ const replicationId =
+ typeof req.query.replicationId === 'string' ? req.query.replicationId : undefined;
+ const result = await this.planService.repairRepo(req.params.id, repairType, replicationId);
+ res.status(result.success ? 200 : 500).json(result);
+ } catch (error: unknown) {
+ const appError = error as AppError;
+ res.status(appError.statusCode || 500).json({
+ success: false,
+ error: appError.message || 'Failed to repair repository',
+ });
+ }
+ }
+
async sendTestBackupNotification(req: Request, res: Response): Promise<void> {
if (
!req.body.planId ||
diff --git a/backend/src/jobs/tasks/BackupTask.ts b/backend/src/jobs/tasks/BackupTask.ts
index 2a8e8e5..394654d 100644
--- a/backend/src/jobs/tasks/BackupTask.ts
+++ b/backend/src/jobs/tasks/BackupTask.ts
@@ -16,14 +16,19 @@ export class BackupTask extends Task {
throw new Error('Missing planId in job payload');
}
- const { planId, backupId } = job.payload;
+ const { planId, backupId, runConfig } = job.payload;
logger.info(`Starting backup job for plan: ${planId}`);
try {
- await this.backupManager.performBackupExecution(planId, backupId, {
- attempts: job.attempts,
- maxAttempts: job.maxAttempts,
- });
+ await this.backupManager.performBackupExecution(
+ planId,
+ backupId,
+ {
+ attempts: job.attempts,
+ maxAttempts: job.maxAttempts,
+ },
+ runConfig
+ );
planLogger('backup', planId, backupId).info(
`Backup job for plan ${planId} completed successfully.`
diff --git a/backend/src/managers/BaseBackupManager.ts b/backend/src/managers/BaseBackupManager.ts
index d83760c..bb44cf0 100644
--- a/backend/src/managers/BaseBackupManager.ts
+++ b/backend/src/managers/BaseBackupManager.ts
@@ -3,13 +3,14 @@ import { runResticCommand } from '../utils/restic/restic';
import { generateResticRepoPath } from '../utils/restic/helpers';
import { runRcloneCommand } from '../utils/rclone/rclone';
import { CronManager } from './CronManager';
-import { BackupPlanArgs, PlanPrune } from '../types/plans';
+import { BackupPlanArgs, BackupVerifiedResult, PlanPrune } from '../types/plans';
import { BackupHandler } from './handlers/BackupHandler';
import { PruneHandler } from './handlers/PruneHandler';
import { jobQueue } from '../jobs/JobQueue';
import { jobProcessor } from '../jobs/JobProcessor';
import { generateUID } from '../utils/helpers';
import { configService } from '../services/ConfigService';
+import { BackupRunConfig } from '../types/backups';
type ScheduleOptions = (BackupPlanArgs | PlanPrune) & {
isActive: boolean;
@@ -177,7 +178,10 @@ export class BaseBackupManager extends EventEmitter {
* This method is used to perform a backup immediately, without waiting for the scheduled time.
* Retries 5 times with a delay of 1 minute between each retry.
*/
- async performBackup(planId: string): Promise<{ success: boolean; result: string }> {
+ async performBackup(
+ planId: string,
+ runConfig?: BackupRunConfig
+ ): Promise<{ success: boolean; result: string }> {
const backupId = generateUID();
const schedules = await this.cronManager.getSchedule(planId);
const backupSchedule = schedules?.find(s => s.type === 'backup');
@@ -186,7 +190,7 @@ export class BaseBackupManager extends EventEmitter {
if (!backupSchedule || !backupSchedule.options) {
return { success: false, result: 'No backup schedule found for this plan.' };
}
- jobQueue.addPriorityJob('Backup', { planId, backupId }, retries, retryDelay * 1000);
+ jobQueue.addPriorityJob('Backup', { planId, backupId, runConfig }, retries, retryDelay * 1000);
const activeBackupJobs = jobProcessor.getActiveBackupJobs();
const maxConcurrentBackups = configService.config.MAX_CONCURRENT_BACKUPS;
const reachedLimit = activeBackupJobs >= maxConcurrentBackups;
@@ -203,7 +207,8 @@ export class BaseBackupManager extends EventEmitter {
async performBackupExecution(
planId: string,
backupId: string,
- retryInfo: { attempts: number; maxAttempts: number }
+ retryInfo: { attempts: number; maxAttempts: number },
+ runConfig?: BackupRunConfig
): Promise<string> {
// Retrieve the schedule and its options from the CronManager
const schedules = await this.cronManager.getSchedule(planId);
@@ -214,7 +219,7 @@ export class BaseBackupManager extends EventEmitter {
}
const options = backupSchedule.options as BackupPlanArgs;
- return await this.backupHandler.execute(planId, backupId, options, retryInfo);
+ return await this.backupHandler.execute(planId, backupId, options, retryInfo, runConfig);
}
async cancelBackup(
@@ -602,4 +607,69 @@ export class BaseBackupManager extends EventEmitter {
});
return { success: false, result: { primary: 'No Backup schedule found' } };
}
+
+ async repairRepo(
+ planId: string,
+ repairType: 'snapshots' | 'index' | 'packs',
+ checkRes: BackupVerifiedResult,
+ options: { storageName: string; storagePath: string }
+ ): Promise<{ success: boolean; result: string }> {
+ try {
+ // Check if encryption is enabled for this plan and if ENCRYPTION_KEY is set when necessary before attempting repair
+ const encKey = configService.config.ENCRYPTION_KEY;
+ const schedules = await this.cronManager.getSchedule(planId);
+ const backupSchedule = schedules?.find(s => s.type === 'backup');
+ const backupOptions = backupSchedule?.options as BackupPlanArgs;
+ const encryption = backupOptions?.settings.encryption;
+ if (encryption && (!encKey || encKey.trim() === '')) {
+ return {
+ success: false,
+ result: 'Encryption is enabled but ENCRYPTION_KEY is not set in environment variables.',
+ };
+ }
+
+ // Run restic repair command to either repair snapshots or index based on the repairType parameter
+ const repoPassword = encryption ? encKey : '';
+ try {
+ const repoPath = generateResticRepoPath(options.storageName, options.storagePath || '');
+ const repairCommand = ['-r', repoPath, 'repair', repairType];
+ if (repairType === 'snapshots') {
+ repairCommand.push('--forget');
+ }
+
+ if (repairType === 'packs') {
+ const resticPackCommandMsg = checkRes.logs.find(log =>
+ log.includes('restic repair packs')
+ );
+ if (resticPackCommandMsg) {
+ const packIdsMatch = resticPackCommandMsg.match(/restic repair packs (.+)/);
+ if (packIdsMatch && packIdsMatch[1]) {
+ const packIds = packIdsMatch[1].split(' ');
+ repairCommand.push(...packIds);
+ } else {
+ return { success: false, result: 'Could not extract pack IDs for repair.' };
+ }
+ }
+ }
+
+ if (!encryption) {
+ repairCommand.push('--insecure-no-password');
+ }
+ const repairResult = await runResticCommand(repairCommand, {
+ RESTIC_PASSWORD: repoPassword,
+ RCLONE_CONFIG_PASS: repoPassword,
+ });
+ return { success: true, result: repairResult };
+ } catch (error: any) {
+ console.warn('[repairRepo] repo Repair Error :', error);
+ return {
+ success: false,
+ result: 'Could Not Repair Restic Repo. Details: ' + error.message,
+ };
+ }
+ } catch (error: any) {
+ console.log('[repairRepo] error :', error);
+ return { success: false, result: 'No Backup schedule found' };
+ }
+ }
}
diff --git a/backend/src/managers/handlers/BackupHandler.ts b/backend/src/managers/handlers/BackupHandler.ts
index de85d94..5fe5e83 100644
--- a/backend/src/managers/handlers/BackupHandler.ts
+++ b/backend/src/managers/handlers/BackupHandler.ts
@@ -11,7 +11,7 @@ import { BackupPlanArgs } from '../../types/plans';
import { runScriptsForEvent } from '../../utils/executeUserScript';
import { configService } from '../../services/ConfigService';
import { ReplicationOrchestrator } from './ReplicationOrchestrator';
-import { BackupMirror } from '../../types/backups';
+import { BackupMirror, BackupRunConfig } from '../../types/backups';
type ResticArgsAndEnv = {
resticArgs: string[];
@@ -59,8 +59,9 @@ export class BackupHandler {
async execute(
planId: string,
backupId: string,
- options: Record<string, any>,
- retryInfo: { attempts: number; maxAttempts: number }
+ options: BackupPlanArgs,
+ retryInfo: { attempts: number; maxAttempts: number },
+ runConfig?: BackupRunConfig
): Promise<string> {
// Prevent the same plan from running concurrently.
if (this.runningBackups.has(planId)) {
@@ -88,20 +89,26 @@ export class BackupHandler {
try {
// --- 1. PRE-BACKUP PHASE ---
- const resticArgsAndEnv = this.createResticBackupArgs(planId, options as BackupPlanArgs);
- await this.preBackupPhase(planId, backupId, options, resticArgsAndEnv);
+ const resticArgsAndEnv = this.createResticBackupArgs(planId, options);
+ await this.preBackupPhase(planId, backupId, options, resticArgsAndEnv, runConfig);
if (this.cancelledBackups.has(planId + backupId)) {
throw new Error('BACKUP_CANCELLED: Backup was cancelled');
}
// --- 2. BACKUP PHASE ---
- const result = await this.executeBackupPhase(planId, backupId, options, resticArgsAndEnv);
+ const result = await this.executeBackupPhase(
+ planId,
+ backupId,
+ options,
+ resticArgsAndEnv,
+ runConfig
+ );
if (this.cancelledBackups.has(planId + backupId)) {
throw new Error('BACKUP_CANCELLED: Backup was cancelled');
}
// --- 3. POST-BACKUP PHASE ---
- await this.postBackupPhase(planId, backupId, options);
+ await this.postBackupPhase(planId, backupId, options, runConfig);
// --- 4. REPLICATION PHASE ---
if (
@@ -207,7 +214,8 @@ export class BackupHandler {
planId: string,
backupId: string,
options: Record<string, any>,
- resticArgsAndEnv: ResticArgsAndEnv
+ resticArgsAndEnv: ResticArgsAndEnv,
+ runConfig?: BackupRunConfig
): Promise<void> {
// Update progress: Pre-backup start
await this.updateProgress(planId, backupId, 'pre-backup', 'PRE_BACKUP_START', false);
@@ -223,30 +231,13 @@ export class BackupHandler {
await this.waitForBackupCreation(planId, backupId);
// Perform dry run
- await this.updateProgress(planId, backupId, 'pre-backup', 'PRE_BACKUP_DRY_RUN_START', false);
-
- let dryRunSummary;
- try {
- dryRunSummary = await this.dryRunBackup(planId, backupId, options, resticArgsAndEnv);
- await this.updateProgress(
- planId,
- backupId,
- 'pre-backup',
- 'PRE_BACKUP_DRY_RUN_COMPLETE',
- true
- );
- } catch (error: any) {
- const errMsg = error?.message || 'Unknown Error';
- await this.updateProgress(
- planId,
- backupId,
- 'pre-backup',
- 'PRE_BACKUP_DRY_RUN_ERROR',
- false,
- errMsg
- );
- throw error;
- }
+ const dryRunSummary = await this.dryRunBackup(
+ planId,
+ backupId,
+ options,
+ resticArgsAndEnv,
+ runConfig
+ );
// Emit backup_start with dry run summary to update the DB record and send notifications.
this.emitter.emit('backup_start', {
@@ -284,7 +275,8 @@ export class BackupHandler {
planId: string,
backupId: string,
options: Record<string, any>,
- resticArgsAndEnv: ResticArgsAndEnv
+ resticArgsAndEnv: ResticArgsAndEnv,
+ runConfig?: BackupRunConfig
): Promise<string> {
// Update progress: Backup operation start
await this.updateProgress(planId, backupId, 'backup', 'BACKUP_OPERATION_START', false);
@@ -293,6 +285,7 @@ export class BackupHandler {
const handlers = this.createHandlers(planId, backupId);
const { resticArgs, resticEnv } = resticArgsAndEnv;
const resticArgsWithBackupTag: string[] = [...resticArgs, '--tag', `backup-${backupId}`];
+ const ignoreErrors = runConfig?.ignoreErrors || false;
try {
// Run the Restic Backup command.
@@ -309,9 +302,21 @@ export class BackupHandler {
}
return result;
} catch (error: any) {
- const errMsg = error?.message || 'Unknown Error';
- await this.updateProgress(planId, backupId, 'backup', 'BACKUP_OPERATION_ERROR', true, errMsg);
- throw error;
+ if (!ignoreErrors) {
+ const errMsg = error?.message || 'Unknown Error';
+ await this.updateProgress(
+ planId,
+ backupId,
+ 'backup',
+ 'BACKUP_OPERATION_ERROR',
+ true,
+ errMsg
+ );
+ throw error;
+ } else {
+ await this.updateProgress(planId, backupId, 'backup', 'BACKUP_OPERATION_COMPLETE', true);
+ return '';
+ }
}
}
@@ -321,7 +326,8 @@ export class BackupHandler {
private async postBackupPhase(
planId: string,
backupId: string,
- options: Record<string, any>
+ options: Record<string, any>,
+ runConfig?: BackupRunConfig
): Promise<void> {
// Update progress: Post-backup start
await this.updateProgress(planId, backupId, 'post-backup', 'POST_BACKUP_START', false);
@@ -338,30 +344,33 @@ export class BackupHandler {
);
// Run pruning and stats update
- await this.updateProgress(planId, backupId, 'post-backup', 'POST_BACKUP_PRUNE_START', false);
- try {
- const pruneHandler = new PruneHandler(this.emitter);
- await pruneHandler.prune(planId, options);
- await this.updateProgress(
- planId,
- backupId,
- 'post-backup',
- 'POST_BACKUP_PRUNE_COMPLETE',
- true
- );
- } catch (error: any) {
- const errorMsg = error?.message || 'Unknown Error';
- console.warn(
- `[BackupHandler]: Failed to prune repository for plan: ${planId}. Error: ${errorMsg}`
- );
- await this.updateProgress(
- planId,
- backupId,
- 'post-backup',
- 'POST_BACKUP_PRUNE_FAILED',
- true,
- errorMsg
- );
+ const skipPrune = runConfig?.skipPrune || false;
+ if (!skipPrune) {
+ await this.updateProgress(planId, backupId, 'post-backup', 'POST_BACKUP_PRUNE_START', false);
+ try {
+ const pruneHandler = new PruneHandler(this.emitter);
+ await pruneHandler.prune(planId, options);
+ await this.updateProgress(
+ planId,
+ backupId,
+ 'post-backup',
+ 'POST_BACKUP_PRUNE_COMPLETE',
+ true
+ );
+ } catch (error: any) {
+ const errorMsg = error?.message || 'Unknown Error';
+ console.warn(
+ `[BackupHandler]: Failed to prune repository for plan: ${planId}. Error: ${errorMsg}`
+ );
+ await this.updateProgress(
+ planId,
+ backupId,
+ 'post-backup',
+ 'POST_BACKUP_PRUNE_FAILED',
+ true,
+ errorMsg
+ );
+ }
}
// Run post-backup repository stats update
@@ -641,33 +650,80 @@ export class BackupHandler {
planId: string,
backupId: string,
options: Record<string, any>,
- resticArgsAndEnv: ResticArgsAndEnv
+ resticArgsAndEnv: ResticArgsAndEnv,
+ runConfig?: BackupRunConfig
): Promise<false | Record<string, any>> {
- const { resticArgs, resticEnv } = resticArgsAndEnv;
- const dryRunArgs = [...resticArgs, '--dry-run'];
- const dryRunEnv = {
- ...resticEnv,
- RESTIC_PASSWORD: options.settings.encryption ? configService.config.ENCRYPTION_KEY : '',
+ const skip = runConfig?.skipDryRun || false;
+ const ignoreErrors = runConfig?.ignoreErrors || false;
+ let dryRunSummary: Record<string, any> = {
+ message_type: 'summary',
+ dry_run: true,
+ dry_run_skipped: true,
+ files_new: 0,
+ files_changed: 0,
+ files_unmodified: 0,
+ dirs_new: 0,
+ dirs_changed: 0,
+ dirs_unmodified: 0,
+ data_blobs: 0,
+ tree_blobs: 0,
+ data_added: 0,
+ data_added_packed: 0,
+ total_files_processed: 0,
+ total_bytes_processed: 0,
+ total_duration: 0,
+ snapshot_id: '',
};
- if (options.method === 'rescue') {
- dryRunArgs.push('--one-file-system');
- }
- const handlers = this.createHandlers(planId, backupId);
- try {
- const dryRunOutput = await runResticCommand(
- dryRunArgs,
- dryRunEnv,
- handlers.onProgress,
- handlers.onError,
- handlers.onComplete
- );
- const outputLines = dryRunOutput.split('\n').filter(line => line.trim() !== '');
- const summaryLine = outputLines[outputLines.length - 1];
- const dryRunSummary = JSON.parse(summaryLine);
+
+ if (!skip) {
+ await this.updateProgress(planId, backupId, 'pre-backup', 'PRE_BACKUP_DRY_RUN_START', false);
+
+ const { resticArgs, resticEnv } = resticArgsAndEnv;
+ const dryRunArgs = [...resticArgs, '--dry-run'];
+ const dryRunEnv = {
+ ...resticEnv,
+ RESTIC_PASSWORD: options.settings.encryption ? configService.config.ENCRYPTION_KEY : '',
+ };
+ if (options.method === 'rescue') {
+ dryRunArgs.push('--one-file-system');
+ }
+ const handlers = this.createHandlers(planId, backupId);
+ try {
+ const dryRunOutput = await runResticCommand(
+ dryRunArgs,
+ dryRunEnv,
+ handlers.onProgress,
+ handlers.onError,
+ handlers.onComplete
+ );
+ const outputLines = dryRunOutput.split('\n').filter(line => line.trim() !== '');
+ const summaryLine = outputLines[outputLines.length - 1];
+ dryRunSummary = JSON.parse(summaryLine);
+ await this.updateProgress(
+ planId,
+ backupId,
+ 'pre-backup',
+ 'PRE_BACKUP_DRY_RUN_COMPLETE',
+ true
+ );
+ return dryRunSummary;
+ } catch (error: any) {
+ if (!ignoreErrors) {
+ await this.updateProgress(
+ planId,
+ backupId,
+ 'pre-backup',
+ 'PRE_BACKUP_DRY_RUN_ERROR',
+ false,
+ error?.message || 'Unknown Error'
+ );
+ throw new Error(`Dry run failed: ${error.message}`);
+ } else {
+ return dryRunSummary;
+ }
+ }
+ } else {
return dryRunSummary;
- } catch (error: any) {
- console.error('[dryRunBackup]: Failed', error.message);
- throw new Error(`Dry run failed: ${error.message}`);
}
}
diff --git a/backend/src/routes/plans.ts b/backend/src/routes/plans.ts
index 1c90706..3cba16b 100644
--- a/backend/src/routes/plans.ts
+++ b/backend/src/routes/plans.ts
@@ -17,6 +17,7 @@ export function createPlanRouter(controller: PlanController, router: Router = Ro
router.post('/:id/action/prune', authM, controller.pruneBackup.bind(controller));
router.post('/:id/action/unlock', authM, controller.unlockRepo.bind(controller));
router.post('/:id/action/checkintegrity', authM, controller.checkIntegrity.bind(controller));
+ router.post('/:id/action/repair', authM, controller.repairRepo.bind(controller));
router.post(
'/:id/action/delete-replication-storage',
authM,
diff --git a/backend/src/services/PlanService.ts b/backend/src/services/PlanService.ts
index 7121e7e..589257a 100644
--- a/backend/src/services/PlanService.ts
+++ b/backend/src/services/PlanService.ts
@@ -8,6 +8,7 @@ import { RestoreStore } from '../stores/RestoreStore';
import { Plan, NewPlan, planInsertSchema, planUpdateSchema } from '../db/schema/plans';
import {
BackupPlanArgs,
+ BackupVerifiedResult,
NewPlanReq,
PlanLogItem,
PlanNotification,
@@ -26,6 +27,7 @@ import { SourceTypes } from '../types/source';
import { sanitizeStoragePath } from '../utils/sanitizeStoragePath';
import { BackupNotification } from '../notifications/BackupNotification';
import { ScheduleReconciler } from './ScheduleReconciler';
+import { BackupRunConfig } from '../types/backups';
/**
* PlanService is the central orchestrator for all business logic related to backup plans.
@@ -293,7 +295,7 @@ export class PlanService {
/**
* Triggers a one-off manual backup for a plan.
*/
- public async performBackup(planId: string): Promise<string> {
+ public async performBackup(planId: string, runConfig?: BackupRunConfig): Promise<string> {
const plan = await this.planStore.getById(planId);
if (!plan) throw new NotFoundError(`Plan with ID ${planId} not found.`);
@@ -302,7 +304,7 @@ export class PlanService {
}
const strategy = this.getStrategy(plan) as BackupStrategy;
- const performResult = await strategy.performBackup(planId);
+ const performResult = await strategy.performBackup(planId, runConfig);
if (!performResult.success) {
throw new AppError(500, performResult.result);
@@ -394,6 +396,54 @@ export class PlanService {
}
}
+ async repairRepo(
+ planId: string,
+ repairType: string,
+ replicationId?: string
+ ): Promise<{ success: boolean; result: Record<string, any> }> {
+ try {
+ const plan = await this.planStore.getById(planId);
+ if (!plan) {
+ throw new NotFoundError('Plan not found');
+ }
+ let storageName;
+ let storagePath;
+ const integrityCheckResAll = plan.verified?.result as Record<string, BackupVerifiedResult>;
+ let integrityCheckRes = integrityCheckResAll['primary'];
+ if (replicationId) {
+ const replicationStorage = plan.settings?.replication?.storages?.find(
+ s => s.replicationId === replicationId
+ );
+ if (!replicationStorage) {
+ throw new NotFoundError('Replication storage not found for the given replicationId');
+ }
+ storageName = replicationStorage.storageName;
+ storagePath = replicationStorage.storagePath;
+ integrityCheckRes = integrityCheckResAll[`mirror_${replicationStorage.storageId}`];
+ } else {
+ if (plan.storage) {
+ storageName =
+ plan.storage.name === 'Local' || plan.storage.name === 'Local Storage'
+ ? 'local'
+ : plan.storage.name;
+ storagePath = plan.storagePath || '';
+ } else {
+ throw new NotFoundError('Storage not found for the given replicationId');
+ }
+ }
+ const strategy = this.getStrategy(plan);
+
+ const result = await strategy.repairRepo(planId, repairType, integrityCheckRes, {
+ storageName,
+ storagePath,
+ });
+ return result;
+ } catch (error: any) {
+ console.log('[repairRepo] error :', error);
+ throw new AppError(500, error?.message || 'Internal Server Error');
+ }
+ }
+
/**
* Removes a replication storage from a plan's replication settings.
* Optionally purges the replicated data from the remote storage.
diff --git a/backend/src/services/events/BackupEventService.ts b/backend/src/services/events/BackupEventService.ts
index a805553..5c6a15c 100644
--- a/backend/src/services/events/BackupEventService.ts
+++ b/backend/src/services/events/BackupEventService.ts
@@ -477,10 +477,11 @@ export class BackupEventService {
: thePlan.settings.replication?.storages?.find(
m => m.storageId === key.replace('mirror_', '')
);
- const storageName =
+ let storageName =
key === 'primary'
? (theStorage as PlanStorageItem)?.name
: (theStorage as PlanReplicationStorage)?.storageName || key;
+ if (storageName === 'Local Storage') storageName = 'local';
const storagePath =
key === 'primary'
? thePlan.storagePath
diff --git a/backend/src/strategies/backup/BackupStrategy.ts b/backend/src/strategies/backup/BackupStrategy.ts
index dc668a4..fd226d9 100644
--- a/backend/src/strategies/backup/BackupStrategy.ts
+++ b/backend/src/strategies/backup/BackupStrategy.ts
@@ -1,12 +1,16 @@
import { StrategyMethodTypes } from '../../types/strategy';
-import { BackupPlanArgs } from '../../types/plans';
+import { BackupPlanArgs, BackupVerifiedResult } from '../../types/plans';
+import { BackupRunConfig } from '../../types/backups';
export interface BackupStrategy {
createBackup(
planId: string,
options: BackupPlanArgs
): Promise<{ success: boolean; result: string }>;
- performBackup(planId: string): Promise<{ success: boolean; result: string }>;
+ performBackup(
+ planId: string,
+ runConfig?: BackupRunConfig
+ ): Promise<{ success: boolean; result: string }>;
updateBackup(
planId: string,
options: Record<string, any>
@@ -53,6 +57,12 @@ export interface BackupStrategy {
newStorageName: string
): Promise<{ success: boolean; result: string }>;
checkIntegrity(planId: string): Promise<{ success: boolean; result: any }>;
+ repairRepo(
+ planId: string,
+ repairType: 'snapshots' | 'index' | 'packs',
+ checkRes: BackupVerifiedResult,
+ options: { storageName: string; storagePath: string }
+ ): Promise<{ success: boolean; result: any }>;
}
export type BackupStrategyTypes = StrategyMethodTypes<BackupStrategy>;
diff --git a/backend/src/strategies/backup/LocalStrategy.ts b/backend/src/strategies/backup/LocalStrategy.ts
index 4258478..246b171 100644
--- a/backend/src/strategies/backup/LocalStrategy.ts
+++ b/backend/src/strategies/backup/LocalStrategy.ts
@@ -1,14 +1,15 @@
import { BackupStrategy } from './BackupStrategy';
-import { BackupPlanArgs } from '../../types/plans';
+import { BackupPlanArgs, BackupVerifiedResult } from '../../types/plans';
import { BaseBackupManager } from '../../managers/BaseBackupManager';
import { readFile } from 'fs/promises';
import { appPaths } from '../../utils/AppPaths';
+import { BackupRunConfig } from '../../types/backups';
export class LocalStrategy implements BackupStrategy {
constructor(protected localAgent: BaseBackupManager) {}
- async performBackup(backupId: string) {
- return await this.localAgent.performBackup(backupId);
+ async performBackup(backupId: string, runConfig?: BackupRunConfig) {
+ return await this.localAgent.performBackup(backupId, runConfig);
}
async createBackup(backupId: string, options: BackupPlanArgs) {
@@ -82,6 +83,15 @@ export class LocalStrategy implements BackupStrategy {
return await this.localAgent.checkIntegrity(planId);
}
+ async repairRepo(
+ planId: string,
+ repairType: 'snapshots' | 'index' | 'packs',
+ checkRes: BackupVerifiedResult,
+ options: { storageName: string; storagePath: string }
+ ): Promise<{ success: boolean; result: any }> {
+ return await this.localAgent.repairRepo(planId, repairType, checkRes, options);
+ }
+
async getBackupProgress(planId: string, backupId: string) {
try {
const filename = `backup-${backupId}.json`;
diff --git a/backend/src/strategies/backup/RemoteStrategy.ts b/backend/src/strategies/backup/RemoteStrategy.ts
index 8d19b11..c11ad77 100644
--- a/backend/src/strategies/backup/RemoteStrategy.ts
+++ b/backend/src/strategies/backup/RemoteStrategy.ts
@@ -1,3 +1,5 @@
+import { BackupVerifiedResult } from '../../types/plans';
+import { BackupRunConfig } from '../../types/backups';
import { BackupStrategy } from './BackupStrategy';
export class RemoteStrategy implements BackupStrategy {
@@ -37,8 +39,8 @@ export class RemoteStrategy implements BackupStrategy {
return await this.publishCommand('REMOVE_REPLICATION_STORAGE', { planId, options });
}
- async performBackup(planId: string) {
- return await this.publishCommand('PERFORM_BACKUP', { planId });
+ async performBackup(planId: string, runConfig?: BackupRunConfig) {
+ return await this.publishCommand('PERFORM_BACKUP', { planId, runConfig });
}
async pauseBackup(planId: string) {
@@ -72,6 +74,15 @@ export class RemoteStrategy implements BackupStrategy {
return await this.publishCommand('CHECK_INTEGRITY', { planId });
}
+ async repairRepo(
+ planId: string,
+ repairType: 'snapshots' | 'index' | 'packs',
+ checkRes: BackupVerifiedResult,
+ options: { storageName: string; storagePath: string }
+ ): Promise<{ success: boolean; result: any }> {
+ return await this.publishCommand('REPAIR_REPO', { planId, repairType, checkRes, options });
+ }
+
publishCommand(action: string, payload: any): Promise<{ success: boolean; result: any }> {
return new Promise((resolve, reject) => {
resolve({ success: true, result: null });
diff --git a/backend/src/types/backups.ts b/backend/src/types/backups.ts
index 4fe550b..2382e68 100644
--- a/backend/src/types/backups.ts
+++ b/backend/src/types/backups.ts
@@ -95,3 +95,9 @@ export interface BackupMirror {
error?: string;
size?: number;
}
+
+export type BackupRunConfig = {
+ skipDryRun?: boolean;
+ skipPrune?: boolean;
+ ignoreErrors?: boolean;
+};
diff --git a/backend/src/types/plans.ts b/backend/src/types/plans.ts
index 15a23f6..11c4f10 100644
--- a/backend/src/types/plans.ts
+++ b/backend/src/types/plans.ts
@@ -79,6 +79,7 @@ export type BackupVerifiedResult = {
logs: string[];
fix?: string;
hasError: boolean;
+ errorType?: string;
};
export type SyncVerifiedResult = {
diff --git a/backend/src/utils/providers/gdrive.ts b/backend/src/utils/providers/gdrive.ts
index da49269..910df52 100644
--- a/backend/src/utils/providers/gdrive.ts
+++ b/backend/src/utils/providers/gdrive.ts
@@ -32,7 +32,7 @@ const googleDriveSettings = [
options: [
{ label: 'Full access (all files)', value: 'drive' },
{ label: 'Read-only access', value: 'drive.readonly' },
- { label: 'Access rclone files only', value: 'drive.file' },
+ { label: 'Access to files only', value: 'drive.file' },
{ label: 'Application Data folder', value: 'drive.appfolder' },
{ label: 'Read-only metadata', value: 'drive.metadata.readonly' },
],
diff --git a/backend/src/utils/restic/restic.ts b/backend/src/utils/restic/restic.ts
index 9a34aa4..060676c 100644
--- a/backend/src/utils/restic/restic.ts
+++ b/backend/src/utils/restic/restic.ts
@@ -270,37 +270,51 @@ export function handleResticCheckResult(
let message = '';
let hasError = true;
let fix = '';
+ let errorType = 'unknown';
const logs: string[] = [];
- if (output.includes('The repository contains damaged pack files')) {
- message = 'A Pack file of a snapshot was damaged.';
- const packFileID = output.match(/pack ([a-f0-9]{64}):/)?.[1];
- fix = `Login to your Machine ${device}.
- Run this command to first to try and repair the pack file:
- \`restic repair -r ${repo} packs ${packFileID}\`
- Then run this command to fix the snapshots if they are still damaged:
- \`restic repair -r ${repo} snapshots --forget \`
- When asked for the password, use the Pluton Encryption key.
- `;
+ if (
+ output.includes('The repository contains damaged pack files') ||
+ (output.includes('pack') && output.includes('does not exist')) ||
+ /id\s+[a-f0-9]+\s+not found in repository/i.test(output) ||
+ output.includes('Pack ID does not match') ||
+ output.includes('Blob ID does not match')
+ ) {
+ errorType = 'pack_file_error';
+ message = 'One or more pack files in the repository are damaged or missing.';
}
+
+ if (
+ output.includes('The repository contains damaged pack files') &&
+ output.includes('restic repair packs')
+ ) {
+ errorType = 'repairable_pack_file_error';
+ message = 'One or more pack files in the repository are damaged.';
+ }
+
if (output.includes('The repository index is damaged')) {
+ errorType = 'index_error';
message = 'The repository index is damaged.';
fix = `Login to your Machine ${device}.
Run this command:
- \`restic repair index -r ${repo}\`
+ \`prestic repair index -r ${repo}\`
When asked for the password, use the Pluton Encryption key.
`;
}
+
if (output.includes('ciphertext verification failed')) {
+ errorType = 'ciphertext_verification_error';
message = 'Ciphertext verification failed.';
fix =
'Ciphertext verification issue is hard to fix. Please ask for help in the Restic forum or their IRC channel. These errors are often caused by hardware problems which must be investigated and fixed. Otherwise, the backup will be damaged again and again.';
}
if (output.includes('failed to authorize account')) {
+ errorType = 'authorization_error';
message = 'Storage Authorization failed.';
hasError = false;
}
if (output.includes('no errors were found')) {
+ errorType = '';
message = 'No Issue Detected.';
hasError = false;
}
@@ -311,5 +325,5 @@ export function handleResticCheckResult(
}
});
- return { message, logs, hasError, fix };
+ return { message, logs, hasError, fix, errorType };
}
diff --git a/frontend/src/@types/plans.ts b/frontend/src/@types/plans.ts
index 021a1c7..6eeec81 100644
--- a/frontend/src/@types/plans.ts
+++ b/frontend/src/@types/plans.ts
@@ -77,6 +77,7 @@ export type PlanVerifiedResult = {
logs: string[];
fix?: string;
hasError: boolean;
+ errorType?: string;
};
export type PlanVerification = {
diff --git a/frontend/src/components/Plan/BackupProgress/BackupProgress.tsx b/frontend/src/components/Plan/BackupProgress/BackupProgress.tsx
index f7d349b..c64779a 100644
--- a/frontend/src/components/Plan/BackupProgress/BackupProgress.tsx
+++ b/frontend/src/components/Plan/BackupProgress/BackupProgress.tsx
@@ -41,7 +41,7 @@ const BackupProgress = ({ item, sourceId, sourceType, planId, type = 'backup' }:
const progressMessage = type === 'backup' ? generateBackupProgressMessage(progressData) : generateRestoreProgressMessage(progressData);
// Check if DryRun progress tracking phase
- const actualBackupStarted = progressData?.events.find((e: any) => e.action === 'BACKUP_OPERATION_START' && e.resticData);
+ const actualBackupStarted = progressData?.events?.find((e: any) => e.action === 'BACKUP_OPERATION_START' && e.resticData);
const isDryRun = type === 'backup' && !actualBackupStarted;
// Extract progress values from restic data or use defaults
diff --git a/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.module.scss b/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.module.scss
index 7dc9aae..6de6408 100644
--- a/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.module.scss
+++ b/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.module.scss
@@ -103,6 +103,25 @@
}
}
+.repairBox {
+ border: 1px solid var(--line-color);
+ padding: 12px;
+ margin: 15px 5px;
+ box-sizing: border-box;
+ border-radius: 6px;
+ border-color: var(--primary-color-mid) #aaacff;
+ background: var(--background-color);
+
+ button {
+ background-color: var(--primary-color);
+ color: var(--primary-text-color);
+ padding: 6px 12px;
+ cursor: pointer;
+ border-radius: 4px;
+ margin-top: 6px;
+ }
+}
+
@media only screen and (max-width: 768px) {
.integrityLogs .integrityLogsHeader {
flex-direction: column;
diff --git a/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.tsx b/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.tsx
index 990d93d..ad6b2e4 100644
--- a/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.tsx
+++ b/frontend/src/components/Plan/PlanIntegrity/PlanIntegrity.tsx
@@ -13,9 +13,10 @@ interface PlanIntegrityProps {
storage: { name: string; type: string; id: string };
replicationStorages: PlanReplicationStorage[];
onClose: () => void;
+ onRepairOpen: (replicationId: string) => void;
}
-const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replicationStorages = [], onClose }: PlanIntegrityProps) => {
+const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replicationStorages = [], onClose, onRepairOpen }: PlanIntegrityProps) => {
const [showContent, setShowContent] = useState('primary');
const integrityCheckMutation = useCheckPlanIntegrity();
@@ -67,6 +68,11 @@ const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replica
.split('\n')
.map((line, index) => <p key={index}>{line.includes('`') ? <code>{line.replace(/`/g, '')}</code> : line}</p>)}
{!backupResData.fix && <p>No Suggestion for this issue.</p>}
+ {(backupResData.errorType === 'pack_file_error' || backupResData.errorType === 'index_error') && (
+ <p>
+ <button onClick={() => onRepairOpen(storageType)}>Open Repo Repair</button> Window for more options.
+ </p>
+ )}
<p>
Learn more about fixing restic repo issues{' '}
<a
@@ -96,6 +102,37 @@ const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replica
return <div className="label error">⛔ Error Found. {backupMessage}</div>;
};
+ const renderRepairContent = (storageType: string) => {
+ const backupResData = getBackupResultByStorage(storageType);
+ return (
+ <div className={classes.repairBox}>
+ {(backupResData?.errorType === 'pack_file_error' || backupResData?.errorType === 'repairable_pack_file_error') && (
+ <div>
+ Some pack files in the repository are either damaged or missing and can be repaired.{' '}
+ <button onClick={() => onRepairOpen(storageType)}>
+ <Icon type="repair" size={13} /> Open Repo Repair Tool
+ </button>
+ </div>
+ )}
+ {backupResData?.errorType === 'index_error' && (
+ <div>
+ The index files in the repository are corrupted and can be repaired.{' '}
+ <button onClick={() => onRepairOpen(storageType)}>
+ <Icon type="repair" size={13} /> Open Repo Repair Tool
+ </button>{' '}
+ </div>
+ )}
+ </div>
+ );
+ };
+
+ const renderRepairOrFixSuggestion = (storageType: string) => {
+ const backupResData = getBackupResultByStorage(storageType);
+ const errorType = backupResData?.errorType;
+ const isRepairable = errorType === 'pack_file_error' || errorType === 'index_error' || errorType === 'repairable_pack_file_error';
+ return isRepairable ? renderRepairContent(storageType) : renderBackupFixSuggestion(storageType);
+ };
+
const renderResultWithReplications = () => {
return (
<div className={`${classes.integrityResult} ${classes.withReplications}`}>
@@ -130,7 +167,7 @@ const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replica
<div className={classes.replicationResultContent}>
{renderBackupStatus(storageType)}
{renderLogs(storageType)}
- {renderBackupFixSuggestion(storageType)}
+ {renderRepairOrFixSuggestion(storageType)}
</div>
)}
</div>
@@ -152,7 +189,7 @@ const PlanIntegrity = ({ planId, taskPending, verificationData, storage, replica
<div className={classes.integrityResult}>
{renderBackupStatus('primary')}
{renderLogs('primary')}
- {renderBackupFixSuggestion('primary')}
+ {renderRepairOrFixSuggestion('primary')}
</div>
) : (
renderResultWithReplications()
diff --git a/frontend/src/components/Plan/PlanItems/PlanItem.tsx b/frontend/src/components/Plan/PlanItems/PlanItem.tsx
index 0320867..6b732d8 100644
--- a/frontend/src/components/Plan/PlanItems/PlanItem.tsx
+++ b/frontend/src/components/Plan/PlanItems/PlanItem.tsx
@@ -79,7 +79,7 @@ const PlanItem = ({ plan, layout = 'list' }: PlanItemProps) => {
return;
}
toast.promise(
- performBackupMutation.mutateAsync(id),
+ performBackupMutation.mutateAsync({ id }),
{
pending: `Starting ${isSync ? 'Sync' : 'Backup'}...`,
success: `${isSync ? 'Sync' : 'Backup'} initiated successfully! 🚀`,
diff --git a/frontend/src/components/Plan/PlanRepair/PlanRepair.module.scss b/frontend/src/components/Plan/PlanRepair/PlanRepair.module.scss
new file mode 100644
index 0000000..5d36ec9
--- /dev/null
+++ b/frontend/src/components/Plan/PlanRepair/PlanRepair.module.scss
@@ -0,0 +1,53 @@
+.repairContainer {
+ position: relative;
+ small {
+ padding: 12px 0;
+ display: block;
+ }
+ .repairContent {
+ border: 1px solid var(--line-color);
+ border-radius: 6px;
+ button {
+ background: var(--background-color);
+ border-radius: 20px;
+ line-height: 1.7em;
+ color: var(--primary-color);
+ padding: 2px 10px;
+ transition: all 0.1s linear;
+ &:hover {
+ background: var(--primary-color);
+ color: var(--primary-text-color);
+ }
+ }
+ .repairTitle {
+ background: var(--background-color);
+ margin-top: 0;
+ font-weight: 600;
+ font-size: 1.1em;
+ padding: 12px;
+ }
+ p {
+ padding: 16px 8px;
+ border-bottom: 1px solid var(--line-color);
+ margin: 0;
+ }
+ p:last-child {
+ border-bottom: none;
+ }
+ }
+ .overlay {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ top: 0;
+ left: 0;
+ opacity: 0.95;
+ background-color: var(--modal-bg);
+ z-index: 3;
+ justify-content: center;
+ align-items: center;
+ display: flex;
+ border: 1px solid var(--line-color);
+ border-radius: 6px;
+ }
+}
diff --git a/frontend/src/components/Plan/PlanRepair/PlanRepair.tsx b/frontend/src/components/Plan/PlanRepair/PlanRepair.tsx
new file mode 100644
index 0000000..ffa63c9
--- /dev/null
+++ b/frontend/src/components/Plan/PlanRepair/PlanRepair.tsx
@@ -0,0 +1,243 @@
+import { toast } from 'react-toastify';
+import { usePausePlan, usePerformBackup, useRepairBackupPlan, useResumePlan } from '../../../services';
+import Icon from '../../common/Icon/Icon';
+import SidePanel from '../../common/SidePanel/SidePanel';
+import classes from './PlanRepair.module.scss';
+
+interface PlanRepairProps {
+ planId: string;
+ errorType: string;
+ onClose: () => void;
+ onOpenIntegrity: () => void;
+}
+
+const PlanRepair = ({ planId, errorType, onClose, onOpenIntegrity }: PlanRepairProps) => {
+ const pauseMutation = usePausePlan();
+ const resumeMutation = useResumePlan();
+
+ const performBackupMutation = usePerformBackup();
+ const repairRepoMutation = useRepairBackupPlan();
+
+ const shouldBeInaccessible =
+ pauseMutation.isPending || resumeMutation.isPending || performBackupMutation.isPending || repairRepoMutation.isPending;
+
+ const pausePlan = () => {
+ toast.promise(
+ pauseMutation.mutateAsync(planId),
+ {
+ pending: 'Pausing backup Plan...',
+ success: 'Backup Plan Paused',
+ error: {
+ render({ data }: any) {
+ return `Failed to Pause Backup Plan. ${data?.message || 'Unknown Error.'}`;
+ },
+ },
+ },
+ { autoClose: 3000 },
+ );
+ };
+
+ const resumePlan = () => {
+ toast.promise(
+ resumeMutation.mutateAsync(planId),
+ {
+ pending: 'Resuming backup Plan...',
+ success: 'Backup Plan Resumed',
+ error: {
+ render({ data }: any) {
+ return `Failed to Resume Backup Plan. ${data?.message || 'Unknown Error.'}`;
+ },
+ },
+ },
+ { autoClose: 3000 },
+ );
+ };
+
+ const runBackup = () => {
+ toast.promise(performBackupMutation.mutateAsync({ id: planId, runConfig: { ignoreErrors: true, skipPrune: true } }), {
+ pending: 'Running backup...',
+ success: 'Backup Started!',
+ error: {
+ render({ data }: any) {
+ return `Failed to Start Backup. ${data?.message || 'Unknown Error.'}`;
+ },
+ },
+ });
+ };
+
+ const repairRepo = (type: 'index' | 'snapshots' | 'packs') => {
+ toast.promise(repairRepoMutation.mutateAsync({ planId, type }), {
+ pending: `Repairing broken ${type}...`,
+ success: `Successfully repaired broken ${type}.`,
+ error: {
+ render({ data }: any) {
+ return `Failed to repair broken ${type}. ${data?.message || 'Unknown Error.'}`;
+ },
+ },
+ });
+ };
+
+ const renderMissingPackRepairContent = () => {
+ return (
+ <div className={classes.repairContent}>
+ <p className={classes.repairTitle}>Fixing Restic Repo with Damaged or Missing Packs</p>
+ <p>
+ <strong>Step 1: </strong> First,{' '}
+ <button onClick={pausePlan} disabled={shouldBeInaccessible}>
+ <Icon type="pause" size={12} /> Pause
+ </button>{' '}
+ the backup plan to prevent any new backup runs from starting.
+ </p>
+ <p>
+ <strong>Step 2: </strong> Download/Backup the index and the snapshots directories from the destination storage.
+ </p>
+ <p>
+ <strong>Step 3: </strong> Then{' '}
+ <button onClick={() => repairRepo('index')} disabled={shouldBeInaccessible}>
+ <Icon type="repair" size={12} /> Repair the Repo Index
+ </button>{' '}
+ to fix missing or damaged pack files.
+ </p>
+ <p>
+ <strong>Step 4: </strong> Then{' '}
+ <button onClick={runBackup} disabled={shouldBeInaccessible}>
+ <Icon type="backup" size={13} /> Run a Backup
+ </button>{' '}
+ to update the Repo Index after repairing it.
+ </p>
+ <p>
+ <strong>Step 5: </strong> Then{' '}
+ <button onClick={onOpenIntegrity} disabled={shouldBeInaccessible}>
+ <Icon type="integrity" size={12} /> Check Integrity
+ </button>{' '}
+ again to see if the repo is fixed.
+ </p>
+ <p>
+ <strong>Step 6: </strong> If that did not fix the issue,{' '}
+ <button onClick={() => repairRepo('snapshots')} disabled={shouldBeInaccessible}>
+ <Icon type="repair" size={12} /> Repair Broken Snapshots
+ </button>{' '}
+ and then{' '}
+ <button onClick={onOpenIntegrity} disabled={shouldBeInaccessible}>
+ <Icon type="integrity" size={12} /> Check Integrity
+ </button>
+ </p>
+ <p>
+ <strong>Step 7: </strong> If the issue is resolved,{' '}
+ <button onClick={resumePlan} disabled={shouldBeInaccessible}>
+ <Icon type="play" size={12} /> Resume
+ </button>{' '}
+ the backup plan.
+ </p>
+ </div>
+ );
+ };
+ const renderPackRepairContent = () => {
+ return (
+ <div className={classes.repairContent}>
+ <p className={classes.repairTitle}>Fixing Restic Repo with Damaged Pack files</p>
+ <p>
+ <strong>Step 1: </strong> First,{' '}
+ <button onClick={pausePlan} disabled={shouldBeInaccessible}>
+ <Icon type="pause" size={12} /> Pause
+ </button>{' '}
+ the backup plan to prevent any new backup runs from starting.
+ </p>
+ <p>
+ <strong>Step 2: </strong> Then{' '}
+ <button onClick={() => repairRepo('packs')} disabled={shouldBeInaccessible}>
+ <Icon type="repair" size={12} /> Repair the Pack Files
+ </button>{' '}
+ to fix missing or damaged pack files.
+ </p>
+ <p>
+ <strong>Step 3: </strong> Then{' '}
+ <button onClick={() => repairRepo('snapshots')} disabled={shouldBeInaccessible}>
+ <Icon type="repair" size={12} /> Repair the Snapshots
+ </button>{' '}
+ to fix the snapshots that relied on the broken pack files.
+ </p>
+ <p>
+ <strong>Step 4: </strong> Then{' '}
+ <button onClick={onOpenIntegrity} disabled={shouldBeInaccessible}>
+ <Icon type="integrity" size={12} /> Check Integrity
+ </button>{' '}
+ again to see if the repo is fixed.
+ </p>
+ <p>
+ <strong>Step 5: </strong> If the issue is resolved,{' '}
+ <button onClick={resumePlan} disabled={shouldBeInaccessible}>
+ <Icon type="play" size={12} /> Resume
+ </button>{' '}
+ the backup plan.
+ </p>
+ </div>
+ );
+ };
+
+ const renderIndexRepairContent = () => {
+ return (
+ <div className={classes.repairContent}>
+ <p className={classes.repairTitle}>Fixing Restic Repo with Damaged Index</p>
+ <p>
+ <strong>Step 1: </strong> First,{' '}
+ <button onClick={pausePlan} disabled={shouldBeInaccessible}>
+ <Icon type="pause" size={12} /> Pause
+ </button>{' '}
+ the backup plan to prevent any new backup runs from starting.
+ </p>
+ <p>
+ <strong>Step 2: </strong> Then{' '}
+ <button onClick={() => repairRepo('index')} disabled={shouldBeInaccessible}>
+ <Icon type="repair" size={12} /> Repair the Index
+ </button>{' '}
+ to fix damaged index files.
+ </p>
+ <p>
+ <strong>Step 3: </strong> Then{' '}
+ <button onClick={onOpenIntegrity} disabled={shouldBeInaccessible}>
+ <Icon type="integrity" size={12} /> Check Integrity
+ </button>{' '}
+ again to see if the repo is fixed.
+ </p>
+ <p>
+ <strong>Step 4: </strong> If the issue is resolved,{' '}
+ <button onClick={resumePlan} disabled={shouldBeInaccessible}>
+ <Icon type="play" size={12} /> Resume
+ </button>{' '}
+ the backup plan.
+ </p>
+ </div>
+ );
+ };
+
+ return (
+ <SidePanel
+ title="Check Backup Integrity"
+ icon={'integrity'}
+ // errorMessage={integrityCheckMutation.error?.message}
+ close={() => onClose()}
+ width="800px"
+ >
+ <div className={classes.repairContainer}>
+ {shouldBeInaccessible && (
+ <div className={classes.overlay}>
+ <Icon type="loading" size={36} />
+ </div>
+ )}
+ {errorType === 'pack_file_error' && renderMissingPackRepairContent()}
+ {errorType === 'repairable_pack_file_error' && renderPackRepairContent()}
+ {errorType === 'index_error' && renderIndexRepairContent()}
+ <small>
+ If performing the above actions does not resolve the issue, please follow this{' '}
+ <a href="https://restic.readthedocs.io/en/stable/077_troubleshooting.html" target="_blank" rel="noopener noreferrer">
+ Restic Troubleshooting Guide
+ </a>
+ .
+ </small>
+ </div>
+ </SidePanel>
+ );
+};
+
+export default PlanRepair;
diff --git a/frontend/src/components/common/Icon/Icon.tsx b/frontend/src/components/common/Icon/Icon.tsx
index 84327af..d060dfc 100644
--- a/frontend/src/components/common/Icon/Icon.tsx
+++ b/frontend/src/components/common/Icon/Icon.tsx
@@ -978,6 +978,18 @@ const Icon = ({ type, color = 'currentColor', size = 16, title = '', classes = '
></path>
</IconWrapper>
)}
+ {type === 'repair' && (
+ <IconWrapper size={size} viewBox="0 0 24 24">
+ <g fill="none" fillRule="evenodd">
+ <path d="m12.593 23.258l-.011.002l-.071.035l-.02.004l-.014-.004l-.071-.035q-.016-.005-.024.005l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427q-.004-.016-.017-.018m.265-.113l-.013.002l-.185.093l-.01.01l-.003.011l.018.43l.005.012l.008.007l.201.093q.019.005.029-.008l.004-.014l-.034-.614q-.005-.018-.02-.022m-.715.002a.02.02 0 0 0-.027.006l-.006.014l-.034.614q.001.018.017.024l.015-.002l.201-.093l.01-.008l.004-.011l.017-.43l-.003-.012l-.01-.01z"></path>
+ <path
+ fill={color}
+ d="M7.527 2.657a7.001 7.001 0 0 1 8.26 9.347l4.599 3.893a3.3 3.3 0 1 1-4.651 4.65l-3.891-4.597a7.001 7.001 0 0 1-9.35-8.26a1.01 1.01 0 0 1 1.72-.432l3.045 3.307l2.297-.845l.847-2.3l-3.309-3.04a1.01 1.01 0 0 1 .433-1.723"
+ ></path>
+ </g>
+ </IconWrapper>
+ )}
+
{type === 'dots-vertical' && (
<IconWrapper size={size} viewBox="0 0 24 24">
<path
diff --git a/frontend/src/components/index.ts b/frontend/src/components/index.ts
index 776c6ed..2fb3552 100644
--- a/frontend/src/components/index.ts
+++ b/frontend/src/components/index.ts
@@ -90,6 +90,7 @@ export { default as PlanTypeSettings } from './Plan/PlanSettings/PlanTypeSetting
export { default as PlanStats } from './Plan/PlanStats/PlanStats';
export { default as PlanUnlockModal } from './Plan/PlanUnlockModal/PlanUnlockModal';
export { default as PlanIntegrity } from './Plan/PlanIntegrity/PlanIntegrity';
+export { default as PlanRepair } from './Plan/PlanRepair/PlanRepair';
export { default as SnapshotViewer } from './Plan/SnapshotViewer/SnapshotViewer';
export { default as SnapshotViewerFile } from './Plan/SnapshotViewer/SnapshotViewerFile';
diff --git a/frontend/src/hooks/usePlanSingleActions.tsx b/frontend/src/hooks/usePlanSingleActions.tsx
index 558ffe9..6caf43a 100644
--- a/frontend/src/hooks/usePlanSingleActions.tsx
+++ b/frontend/src/hooks/usePlanSingleActions.tsx
@@ -97,30 +97,33 @@ export const usePlanSingleActions = (): {
const toastId = toast.loading(`Starting ${isSync ? 'Sync' : 'Backup'}...`);
- performBackupMutation.mutate(plan.id, {
- onSuccess: (data) => {
- const msg = data?.message || `${isSync ? 'Sync' : 'Backup'} initiated successfully! 🚀`;
- const notStarted = !isSync && data?.message && data?.message.includes('reached the concurrency limit');
- toast.update(toastId, {
- render: isSync ? msg : notStarted ? data?.message : 'Backup initiated successfully!',
- type: 'success',
- isLoading: false,
- autoClose: 3000,
- });
- if (!isSync && !notStarted) {
- navigate(`/plan/${plan.id}?pendingbackup=1`);
- }
- },
- onError: (error: any) => {
- toast.update(toastId, {
- render: `${isSync ? 'Sync' : 'Backup'} failed to start. ${error?.message || 'Unknown Error.'}`,
- type: 'error',
- isLoading: false,
- autoClose: false,
- closeButton: true,
- });
+ performBackupMutation.mutate(
+ { id: plan.id },
+ {
+ onSuccess: (data) => {
+ const msg = data?.message || `${isSync ? 'Sync' : 'Backup'} initiated successfully! 🚀`;
+ const notStarted = !isSync && data?.message && data?.message.includes('reached the concurrency limit');
+ toast.update(toastId, {
+ render: isSync ? msg : notStarted ? data?.message : 'Backup initiated successfully!',
+ type: 'success',
+ isLoading: false,
+ autoClose: 3000,
+ });
+ if (!isSync && !notStarted) {
+ navigate(`/plan/${plan.id}?pendingbackup=1`);
+ }
+ },
+ onError: (error: any) => {
+ toast.update(toastId, {
+ render: `${isSync ? 'Sync' : 'Backup'} failed to start. ${error?.message || 'Unknown Error.'}`,
+ type: 'error',
+ isLoading: false,
+ autoClose: false,
+ closeButton: true,
+ });
+ },
},
- });
+ );
};
return {
diff --git a/frontend/src/routes/PlanSingle/PlanSingle.tsx b/frontend/src/routes/PlanSingle/PlanSingle.tsx
index 7b19c6b..02aea0f 100644
--- a/frontend/src/routes/PlanSingle/PlanSingle.tsx
+++ b/frontend/src/routes/PlanSingle/PlanSingle.tsx
@@ -15,10 +15,13 @@ import PlanRemoveModal from '../../components/Plan/PlanRemoveModal/PlanRemoveMod
import PlanProgress from '../../components/Plan/PlanProgress/PlanProgress';
import PlanBackups from '../../components/Plan/PlanBackups/PlanBackups';
import PlanIntegrity from '../../components/Plan/PlanIntegrity/PlanIntegrity';
+import PlanRepair from '../../components/Plan/PlanRepair/PlanRepair';
+import { PlanVerifiedResult } from '../..';
const PlanSingle = () => {
const [showMoreOptions, setShowMoreOptions] = useState(false);
const [showIntegrityModal, setShowIntegrityModal] = useState(false);
+ const [showRepoRepair, setShowRepoRepair] = useState('');
const { id } = useParams();
const EditPlanModal = useComponentOverride('EditPlan', EditPlan);
@@ -198,6 +201,20 @@ const PlanSingle = () => {
storage={plan.storage}
replicationStorages={plan.settings.replication?.enabled ? plan.settings.replication.storages : []}
onClose={() => setShowIntegrityModal(false)}
+ onRepairOpen={(replicationId) => {
+ setShowIntegrityModal(false);
+ setShowRepoRepair(replicationId);
+ }}
+ />
+ )}
+ {showRepoRepair && !isSync && (
+ <PlanRepair
+ planId={id}
+ errorType={
+ (plan.verified?.result[showRepoRepair as keyof typeof plan.verified.result] as PlanVerifiedResult)?.errorType || 'unknown'
+ }
+ onClose={() => setShowRepoRepair('')}
+ onOpenIntegrity={() => setShowIntegrityModal(true)}
/>
)}
{showDeleteModal && (
diff --git a/frontend/src/services/plans.ts b/frontend/src/services/plans.ts
index f4d7d68..a5c8943 100644
--- a/frontend/src/services/plans.ts
+++ b/frontend/src/services/plans.ts
@@ -3,6 +3,12 @@ import { toast } from 'react-toastify';
import { API_URL } from '../utils/constants';
import { NewPlanSettings, Plan, PlanNotification } from '../@types/plans';
+type BackupRunConfig = {
+ skipDryRun?: boolean;
+ skipPrune?: boolean;
+ ignoreErrors?: boolean;
+};
+
// Get All Plans
export async function getAllPlans() {
const url = new URL(`${API_URL}/plans`);
@@ -227,12 +233,13 @@ export function useDeletePlan() {
}
// Perform Backup
-export async function performBackup(id: string) {
+export async function performBackup({ id, runConfig }: { id: string; runConfig?: BackupRunConfig }) {
const header = new Headers({ 'Content-Type': 'application/json', Accept: 'application/json' });
const res = await fetch(`${API_URL}/plans/${id}/action/backup`, {
method: 'POST',
credentials: 'include',
headers: header,
+ body: JSON.stringify({ runConfig }),
});
const data = await res.json();
if (!data.success) {
@@ -468,6 +475,35 @@ export function useCheckPlanIntegrity() {
});
}
+export async function repairBackupPlan({ planId, type, replicationId }: { planId: string; type: string; replicationId?: string }) {
+ // const header = new Headers({ 'Content-Type': 'application/json', Accept: 'application/json' });
+ const res = await fetch(`${API_URL}/plans/${planId}/action/repair?type=${type}${replicationId ? `&replicationId=${replicationId}` : ''}`, {
+ method: 'POST',
+ credentials: 'include',
+ // headers: header,
+ });
+ // Check if response is ok
+ const data = await res.json();
+ if (!data.success) {
+ throw new Error(data.error);
+ }
+ return data;
+}
+
+export function useRepairBackupPlan() {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: repairBackupPlan,
+ onSuccess: (res, payload) => {
+ queryClient.invalidateQueries({ queryKey: ['plan', payload.planId] });
+ console.log('res :', payload, res);
+ },
+ onError: (error, payload) => {
+ console.error('Error repairing backup plan for planId:', payload.planId, error);
+ },
+ });
+}
+
export async function sendTestNotificationRequest(payload: {
planId: string;
notificationCase: string;