Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): attempt to delete failed backups immediately after failure #13995

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -165,6 +165,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 @@ -207,5 +208,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);
zackpollard marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
3 changes: 3 additions & 0 deletions server/src/services/backup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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
Loading