mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
fix(server): attempt to delete failed backups immediately after failure (#13995)
This commit is contained in:
parent
7aacc92699
commit
5097c92494
2 changed files with 11 additions and 0 deletions
|
@ -146,6 +146,7 @@ describe(BackupService.name, () => {
|
||||||
storageMock.readdir.mockResolvedValue([]);
|
storageMock.readdir.mockResolvedValue([]);
|
||||||
processMock.spawn.mockReturnValue(mockSpawn(0, 'data', ''));
|
processMock.spawn.mockReturnValue(mockSpawn(0, 'data', ''));
|
||||||
storageMock.rename.mockResolvedValue();
|
storageMock.rename.mockResolvedValue();
|
||||||
|
storageMock.unlink.mockResolvedValue();
|
||||||
systemMock.get.mockResolvedValue(systemConfigStub.backupEnabled);
|
systemMock.get.mockResolvedValue(systemConfigStub.backupEnabled);
|
||||||
storageMock.createWriteStream.mockReturnValue(new PassThrough());
|
storageMock.createWriteStream.mockReturnValue(new PassThrough());
|
||||||
});
|
});
|
||||||
|
@ -188,5 +189,12 @@ describe(BackupService.name, () => {
|
||||||
const result = await sut.handleBackupDatabase();
|
const result = await sut.handleBackupDatabase();
|
||||||
expect(result).toBe(JobStatus.FAILED);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -163,6 +163,9 @@ export class BackupService extends BaseService {
|
||||||
await this.storageRepository.rename(backupFilePath, backupFilePath.replace('.tmp', ''));
|
await this.storageRepository.rename(backupFilePath, backupFilePath.replace('.tmp', ''));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('Database Backup Failure', 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;
|
return JobStatus.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue