integrity: add stats
This commit is contained in:
+14
-9
@@ -24,11 +24,13 @@ async function verify(backup, backupSite, progressCallback) {
|
||||
|
||||
if (backup === null) return [`${backup.id} is missing in database`];
|
||||
|
||||
const stats = { startTime: Date.now(), duration: null };
|
||||
|
||||
const [downloadError, backupInfoBuffer] = await safe(downloadBackupInfo(backupSite, backup));
|
||||
if (downloadError) {
|
||||
const messages = [`Failed to download ${backup.remotePath}.backupinfo: ${downloadError.message}`];
|
||||
await backups.setIntegrityResult(backup, 'failed', { messages });
|
||||
return;
|
||||
stats.duration = Date.now() - stats.startTime;
|
||||
return { stats, messages };
|
||||
}
|
||||
|
||||
const validSignature = crypto.verify(null /* algo */, backupInfoBuffer, backupSite.integrityKeyPair.publicKey, Buffer.from(backup.integrity.signature, 'hex'));
|
||||
@@ -47,7 +49,8 @@ async function verify(backup, backupSite, progressCallback) {
|
||||
|
||||
debug(`verified: ${JSON.stringify(verifyMessages, null, 4)}`);
|
||||
|
||||
return messages;
|
||||
stats.duration = Date.now() - stats.startTime;
|
||||
return { stats, messages };
|
||||
}
|
||||
|
||||
async function check(backupId, progressCallback) {
|
||||
@@ -57,18 +60,20 @@ async function check(backupId, progressCallback) {
|
||||
const backupSite = await backupSites.get(backup.siteId);
|
||||
if (!backupSite) throw new BoxError(BoxError.BAD_FIELD, 'Backup site not found');
|
||||
|
||||
const aggregatedStats = { startTime: Date.now(), duration: null };
|
||||
const aggregatedMessages = [];
|
||||
for (const depId of backup.dependsOn) {
|
||||
const depBackup = await backups.get(depId);
|
||||
const messages = await verify(depBackup, backupSite, progressCallback);
|
||||
const result = await verify(depBackup, backupSite, progressCallback); // { stats, messages }
|
||||
|
||||
await backups.setIntegrityResult(backup, messages.length === 0 ? 'passed' : 'failed', { messages });
|
||||
if (messages.length) aggregatedMessages.push(`Integrity check of dependent backup ${depBackup.remotePath} failed`);
|
||||
await backups.setIntegrityResult(backup, result.messages.length === 0 ? 'passed' : 'failed', result);
|
||||
if (result.messages.length) aggregatedMessages.push(`Integrity check of dependent backup ${depBackup.remotePath} failed`);
|
||||
}
|
||||
|
||||
const messages = await verify(backup, backupSite, progressCallback);
|
||||
aggregatedMessages.push(...messages);
|
||||
await backups.setIntegrityResult(backup, aggregatedMessages.length === 0 ? 'passed' : 'failed', { messages: aggregatedMessages });
|
||||
const result = await verify(backup, backupSite, progressCallback);
|
||||
aggregatedStats.duration = Date.now() - aggregatedStats.startTime;
|
||||
aggregatedMessages.push(...result.messages);
|
||||
await backups.setIntegrityResult(backup, aggregatedMessages.length === 0 ? 'passed' : 'failed', { stats: aggregatedStats, messages: aggregatedMessages });
|
||||
}
|
||||
|
||||
export default {
|
||||
|
||||
Reference in New Issue
Block a user