Skip to content

Commit

Permalink
feat: Configurable temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
avaly committed Aug 19, 2019
1 parent d3cc6d4 commit 25bbfd7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module.exports = {
// '/mnt/nas',
// '/media/nas',
],
// Custom temporary directory for encryption/archiving operations
tempDir: '/tmp/backup-to-cloud',
// The S3 bucket name to use for backup
// Note: the bucket needs to be created before
s3bucket: 'REPLACE-ME-WITH-YOUR-BUCKET-NAME',
Expand Down
1 change: 1 addition & 0 deletions config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ module.exports = Object.assign({}, config, {
FIXTURES_DIR + path.sep + 'ham',
],
s3bucket: 'test-bucket',
tempDir: path.resolve(__dirname, 'tmp', 'tmp'),
});
6 changes: 3 additions & 3 deletions lib/Backuper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Backuper {
}
const isSessionMaxed = this.sessionSize >= config.maxSessionSize;

utils.debug(`Backuper.next sessionSize=${this.sessionSize}`);
utils.debug(`Backuper.next sessionSize=${prettyBytes(this.sessionSize)}`);

if (!isSessionMaxed) {
const nextFileToAdd = await this.getNextToAdd();
Expand All @@ -82,8 +82,8 @@ class Backuper {
}
} else {
utils.debug(
`Backuper.next sessionSize=${this.sessionSize} ` +
`maxSessionSize=${config.maxSessionSize}`,
`Backuper.next sessionSize=${prettyBytes(this.sessionSize)} ` +
`maxSessionSize=${prettyBytes(config.maxSessionSize)}`,
);
}

Expand Down
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ const utils = {
},

tempFile: prefix => {
const tempDir = config.tempDir || os.tmpdir();
utils.mkdir(tempDir);

let file;
do {
file = os.tmpdir() + '/backup-to-cloud-' + prefix + crypto.randomBytes(6).readUInt32LE(0);
file = `${tempDir}/${prefix}${crypto.randomBytes(6).readUInt32LE(0)}`;
} while (fs.existsSync(file));

return file;
},

Expand Down
2 changes: 1 addition & 1 deletion test/backuper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('backuper', () => {
assert.include(output, 'This is a DRY run!');
assert.include(output, 'Backuper.start: locals=9 / remotes=0');
assert.include(output, 'Backuper.add file:');
assert.include(output, 'Backuper.next sessionSize=1024 maxSessionSize=1024');
assert.include(output, 'Backuper.next sessionSize=1.02 kB maxSessionSize=1.02 kB');
assert.include(output, 'Transfer result MAX_SESSION_SIZE');
})
.then(utils.getAWSLog)
Expand Down

0 comments on commit 25bbfd7

Please sign in to comment.