From 8c81a97a4bfbe797f9cc96a70f5e6bdd31e8a4cf Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Thu, 26 Oct 2017 11:27:36 -0700 Subject: [PATCH] Check that the backup location has perms to create a directory The backup itself runs as root and this works fine. But when rotating the backup, the copy fails because it is unable to create a directory. --- src/storage/filesystem.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/storage/filesystem.js b/src/storage/filesystem.js index bc47e9902..8d31f35d5 100644 --- a/src/storage/filesystem.js +++ b/src/storage/filesystem.js @@ -163,14 +163,15 @@ function testConfig(apiConfig, callback) { if ('noHardlinks' in apiConfig && typeof apiConfig.noHardlinks !== 'boolean') return callback(new BackupsError(BackupsError.BAD_FIELD, 'noHardlinks must be boolean')); fs.stat(apiConfig.backupFolder, function (error, result) { - if (error) { - debug('testConfig: %s', apiConfig.backupFolder, error); - return callback(new BackupsError(BackupsError.BAD_FIELD, 'Directory does not exist or cannot be accessed')); - } - + if (error) return callback(new BackupsError(BackupsError.BAD_FIELD, 'Directory does not exist or cannot be accessed: ' + error.message)); if (!result.isDirectory()) return callback(new BackupsError(BackupsError.BAD_FIELD, 'Backup location is not a directory')); - callback(null); + mkdirp(path.join(apiConfig.backupFolder, 'snapshot'), function (error) { + if (error && error.code === 'EACCES') return callback(new BackupsError(BackupsError.BAD_FIELD, `Access denied. Run "chown yellowtent:yellowtent ${apiConfig.backupFolder}" on the server`)); + if (error) return callback(new BackupsError(BackupsError.BAD_FIELD, error.message)); + + callback(null); + }); }); }