rsync: add fileCount to stats and fix integrity collection

This commit is contained in:
Girish Ramakrishnan
2025-08-13 20:59:09 +05:30
parent 67f0801453
commit 2607ad2e24
3 changed files with 45 additions and 15 deletions

View File

@@ -85,7 +85,12 @@ async function sync(backupTarget, remotePath, dataLayout, progressCallback) {
const cacheFile = path.join(paths.BACKUP_INFO_DIR, backupTarget.id, `${dataLayout.getBasename()}.sync.cache`);
const { delQueue, addQueue, integrityMap } = await syncer.sync(dataLayout, cacheFile);
debug(`sync: processing ${delQueue.length} deletes and ${addQueue.length} additions`);
const aggredgatedStats = { added: addQueue.length, deleted: delQueue.length, size: 0, startTime: Date.now() };
const aggregatedStats = {
size: [...integrityMap.values()].reduce((sum, { size }) => sum + size, 0),
fileCount: integrityMap.size + addQueue.length,
startTime: Date.now(),
totalMsecs: 0
};
async function processSyncerChange(change) {
debug('sync: processing task: %j', change);
@@ -105,9 +110,9 @@ async function sync(backupTarget, remotePath, dataLayout, progressCallback) {
debug(`Adding ${change.path} position ${change.position} try ${retryCount}`);
const uploader = await backupTargets.storageApi(backupTarget).upload(backupTarget.config, fullPath);
const { stats, integrity } = await addFile(dataLayout.toLocalPath('./' + change.path), backupTarget.encryption, uploader, progressCallback);
const { integrity } = await addFile(dataLayout.toLocalPath('./' + change.path), backupTarget.encryption, uploader, progressCallback);
integrityMap.set(destPath, integrity);
aggredgatedStats.size += stats.size;
aggregatedStats.size += integrity.size;
});
}
}
@@ -120,10 +125,10 @@ async function sync(backupTarget, remotePath, dataLayout, progressCallback) {
debug('sync: done processing adds. error: %o', addError);
if (addError) throw addError;
await syncer.finalize(cacheFile);
await syncer.finalize(integrityMap, cacheFile);
return {
stats: aggredgatedStats,
stats: { ...aggregatedStats, totalMsecs: Date.now()-aggregatedStats.startTime },
integrity: [...integrityMap.entries()].sort(([a], [b]) => a < b) // for readability, order the entries
};
}