Move backup config fetching into storage backend

This commit is contained in:
Johannes Zellner
2016-09-19 15:03:38 +02:00
parent 0bfc533e44
commit 4a9a6dc232
5 changed files with 86 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ exports = module.exports = {
getAppBackupDetails: getAppBackupDetails,
getRestoreUrl: getRestoreUrl,
getAppRestoreConfig: getAppRestoreConfig,
getLocalFilePath: getLocalFilePath,
copyObject: copyObject
@@ -12,7 +13,8 @@ exports = module.exports = {
var assert = require('assert'),
fs = require('fs'),
path = require('path');
path = require('path'),
safe = require('safetydance');
var FALLBACK_BACKUP_FOLDER = '/var/backups';
@@ -57,6 +59,20 @@ function getRestoreUrl(apiConfig, filename, callback) {
callback(null, { url: restoreUrl });
}
function getAppRestoreConfig(apiConfig, backupId, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof backupId, 'string');
assert.strictEqual(typeof callback, 'function');
var backupFolder = apiConfig.backupFolder || FALLBACK_BACKUP_FOLDER;
var configFilename = backupId.replace(/\.tar\.gz$/, '.json');
var restoreConfig = safe.require(path.join(backupFolder, configFilename));
if (!restoreConfig) return callback(new Error('No app backup config found'));
callback(null, restoreConfig);
}
function getLocalFilePath(apiConfig, filename, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof filename, 'string');