diff --git a/src/backuptask.js b/src/backuptask.js index d59c6740e..7ce5bd9a1 100644 --- a/src/backuptask.js +++ b/src/backuptask.js @@ -53,7 +53,7 @@ async function checkPreconditions(backupConfig, dataLayout) { // check mount status before uploading const status = await backups.ensureMounted(); - debug(`upload: mount point status is ${JSON.stringify(status)}`); + debug(`checkPreconditions: mount point status is ${JSON.stringify(status)}`); if (status.state !== 'active') throw new BoxError(BoxError.MOUNT_ERROR, `Backup endpoint is not active: ${status.message}`); // check availabe size. this requires root for df to work @@ -61,8 +61,11 @@ async function checkPreconditions(backupConfig, dataLayout) { let used = 0; for (const localPath of dataLayout.localPaths()) { debug(`checkPreconditions: getting disk usage of ${localPath}`); - const result = await shell.spawn('du', [ '-Dsb', '--exclude=*.lock', '--exclude=dovecot.list.index.log.*', localPath], {}); - used += parseInt(result, 10); + // du can error when files go missing as it is computing the size. it still prints some size anyway + // to match df output in getAvailableSize() we must use disk usage size here and not apparent size + const [duError, result] = await safe(shell.spawn('du', [ '--dereference-args', '--summarize', '--block-size=1', '--exclude=*.lock', '--exclude=dovecot.list.index.log.*', localPath], { encoding: 'utf8' })); + if (duError) debug(`checkPreconditions: du error for ${localPath}. code: ${duError.code} stderror: ${duError.stderr}`); + used += parseInt(duError ? duError.stdout : result, 10); } debug(`checkPreconditions: total required=${used} available=${available}`); diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index 76ecbfcfd..7df81e395 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -40,10 +40,10 @@ const assert = require('assert'), safe = require('safetydance'), shell = require('../shell.js')('filesystem'); -// the du call in the function below requires root async function getAvailableSize(apiConfig) { assert.strictEqual(typeof apiConfig, 'object'); + // note that df returns the disk size (as opposed to the apparent size) const [error, dfResult] = await safe(df.file(apiConfig.rootPath)); if (error) throw new BoxError(BoxError.FS_ERROR, `Error when checking for disk space: ${error.message}`);