backup size: display stats correctly

This commit is contained in:
Girish Ramakrishnan
2025-10-01 17:19:58 +02:00
parent f69bdd1ac4
commit 832eca2d9c
5 changed files with 29 additions and 13 deletions

View File

@@ -43,7 +43,7 @@ async function addFile(sourceFile, encryption, uploader, progressCallback) {
const [openError, sourceHandle] = await safe(fs.promises.open(sourceFile, 'r'));
if (openError) {
debug(`addFile: ignoring disappeared file: ${sourceFile}`);
return;
return null;
}
const sourceStream = sourceHandle.createReadStream(sourceFile, { autoClose: true });
@@ -69,6 +69,7 @@ async function addFile(sourceFile, encryption, uploader, progressCallback) {
// debug(`addFile: pipeline finished: ${JSON.stringify(ps.stats())}`);
await uploader.finish();
return {
stats: ps.stats(),
integrity: { size: ps.stats().transferred, sha256: hash.digest('hex') }
@@ -84,11 +85,12 @@ async function sync(backupSite, remotePath, dataLayout, progressCallback) {
// the number here has to take into account the s3.upload partSize (which is 10MB). So 20=200MB
const concurrency = backupSite.limits?.syncConcurrency || (backupSite.provider === 's3' ? 20 : 10);
const cacheFile = path.join(paths.BACKUP_INFO_DIR, backupSite.id, `${dataLayout.getBasename()}.sync.cache`);
const { delQueue, addQueue, integrityMap } = await syncer.sync(dataLayout, cacheFile);
const { delQueue, addQueue, integrityMap } = await syncer.sync(dataLayout, cacheFile); // integrityMap is unchanged files
debug(`sync: processing ${delQueue.length} deletes and ${addQueue.length} additions`);
const aggregatedStats = {
transferred: 0,
size: [...integrityMap.values()].reduce((sum, { size }) => sum + size, 0),
fileCount: integrityMap.size + addQueue.length,
fileCount: addQueue.length + integrityMap.size, // final file count, not the transferred file count
startTime: Date.now(),
totalMsecs: 0
};
@@ -111,9 +113,11 @@ async function sync(backupSite, remotePath, dataLayout, progressCallback) {
debug(`Adding ${change.path} position ${change.position} try ${retryCount}`);
const uploader = await backupSites.storageApi(backupSite).upload(backupSite.config, fullPath);
const { integrity } = await addFile(dataLayout.toLocalPath('./' + change.path), backupSite.encryption, uploader, progressCallback);
integrityMap.set(destPath, integrity);
aggregatedStats.size += integrity.size;
const result = await addFile(dataLayout.toLocalPath('./' + change.path), backupSite.encryption, uploader, progressCallback);
if (!result) return; // this can happen if the file disappeared on us
integrityMap.set(destPath, result.integrity);
aggregatedStats.transferred += result.stats.transferred;
aggregatedStats.size += result.stats.transferred;
});
}
}