backup size: display stats correctly
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,12 +169,14 @@ async function tarPack(dataLayout, encryption, uploader, progressCallback) {
|
||||
|
||||
const [error] = await pipeline; // already wrapped in safe()
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `tarPack pipeline error: ${error.message}`);
|
||||
debug(`tarPack: pipeline finished: ${JSON.stringify(ps.stats())}`);
|
||||
|
||||
const stats = ps.stats();
|
||||
debug(`tarPack: pipeline finished: ${JSON.stringify(stats)}`);
|
||||
|
||||
await uploader.finish();
|
||||
return {
|
||||
stats: { fileCount, ...ps.stats() },
|
||||
integrity: { size: ps.stats().transferred, fileCount, sha256: hash.digest('hex') }
|
||||
stats: { fileCount, size: stats.transferred, ...stats },
|
||||
integrity: { size: stats.transferred, fileCount, sha256: hash.digest('hex') }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user