Skip to content

Commit

Permalink
fix(server): attempt to delete failed backups immediately after failu…
Browse files Browse the repository at this point in the history
  • Loading branch information
zackpollard authored and bdavis2-PCTY committed Nov 18, 2024
1 parent 65ac16a commit fb9dc81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/src/services/backup.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe(BackupService.name, () => {
storageMock.readdir.mockResolvedValue([]);
processMock.spawn.mockReturnValue(mockSpawn(0, 'data', ''));
storageMock.rename.mockResolvedValue();
storageMock.unlink.mockResolvedValue();
systemMock.get.mockResolvedValue(systemConfigStub.backupEnabled);
storageMock.createWriteStream.mockReturnValue(new PassThrough());
});
Expand Down Expand Up @@ -188,5 +189,12 @@ describe(BackupService.name, () => {
const result = await sut.handleBackupDatabase();
expect(result).toBe(JobStatus.FAILED);
});
it('should ignore unlink failing and still return failed job status', async () => {
processMock.spawn.mockReturnValueOnce(mockSpawn(1, '', 'error'));
storageMock.unlink.mockRejectedValue(new Error('error'));
const result = await sut.handleBackupDatabase();
expect(storageMock.unlink).toHaveBeenCalled();
expect(result).toBe(JobStatus.FAILED);
});
});
});
3 changes: 3 additions & 0 deletions server/src/services/backup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export class BackupService extends BaseService {
await this.storageRepository.rename(backupFilePath, backupFilePath.replace('.tmp', ''));
} catch (error) {
this.logger.error('Database Backup Failure', error);
await this.storageRepository
.unlink(backupFilePath)
.catch((error) => this.logger.error('Failed to delete failed backup file', error));
return JobStatus.FAILED;
}

Expand Down

0 comments on commit fb9dc81

Please sign in to comment.