Send resolved path to the storage APIs
This commit is contained in:
@@ -57,27 +57,16 @@ function getBackupCredentials(apiConfig, callback) {
|
||||
callback(null, credentials);
|
||||
}
|
||||
|
||||
function getBackupFilePath(apiConfig, backupId) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
|
||||
const FILE_TYPE = apiConfig.key ? '.tar.gz.enc' : '.tar.gz';
|
||||
|
||||
return path.join(apiConfig.prefix, backupId+FILE_TYPE);
|
||||
}
|
||||
|
||||
// storage api
|
||||
function upload(apiConfig, backupId, sourceDir, callback) {
|
||||
function upload(apiConfig, backupFilePath, sourceDir, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof backupFilePath, 'string');
|
||||
assert.strictEqual(typeof sourceDir, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback = once(callback);
|
||||
|
||||
var backupFilePath = getBackupFilePath(apiConfig, backupId);
|
||||
|
||||
debug('[%s] backup: %s -> %s', backupId, sourceDir, backupFilePath);
|
||||
debug('backup: %s -> %s', sourceDir, backupFilePath);
|
||||
|
||||
getBackupCredentials(apiConfig, function (error, credentials) {
|
||||
if (error) return callback(error);
|
||||
@@ -94,7 +83,7 @@ function upload(apiConfig, backupId, sourceDir, callback) {
|
||||
// s3.upload automatically does a multi-part upload. we set queueSize to 1 to reduce memory usage
|
||||
s3.upload(params, { partSize: 10 * 1024 * 1024, queueSize: 1 }, function (error) {
|
||||
if (error) {
|
||||
debug('[%s] backup: s3 upload error.', backupId, error);
|
||||
debug('[%s] backup: s3 upload error.', backupFilePath, error);
|
||||
return callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
}
|
||||
|
||||
@@ -105,17 +94,15 @@ function upload(apiConfig, backupId, sourceDir, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function download(apiConfig, backupId, destination, callback) {
|
||||
function download(apiConfig, backupFilePath, destination, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof backupFilePath, 'string');
|
||||
assert.strictEqual(typeof destination, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback = once(callback);
|
||||
|
||||
var backupFilePath = getBackupFilePath(apiConfig, backupId);
|
||||
|
||||
debug('[%s] restore: %s -> %s', backupId, backupFilePath, destination);
|
||||
debug('restore: %s -> %s', backupFilePath, destination);
|
||||
|
||||
getBackupCredentials(apiConfig, function (error, credentials) {
|
||||
if (error) return callback(error);
|
||||
@@ -133,7 +120,7 @@ function download(apiConfig, backupId, destination, callback) {
|
||||
// TODO ENOENT for the mock, fix upstream!
|
||||
if (error.code === 'NoSuchKey' || error.code === 'ENOENT') return callback(new BackupsError(BackupsError.NOT_FOUND));
|
||||
|
||||
debug('[%s] restore: s3 stream error.', backupId, error);
|
||||
debug('[%s] restore: s3 stream error.', backupFilePath, error);
|
||||
callback(new BackupsError(BackupsError.EXTERNAL_ERROR, error.message));
|
||||
});
|
||||
|
||||
@@ -141,10 +128,10 @@ function download(apiConfig, backupId, destination, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function copy(apiConfig, oldBackupId, newBackupId, callback) {
|
||||
function copy(apiConfig, oldFilePath, newFilePath, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof oldBackupId, 'string');
|
||||
assert.strictEqual(typeof newBackupId, 'string');
|
||||
assert.strictEqual(typeof oldFilePath, 'string');
|
||||
assert.strictEqual(typeof newFilePath, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getBackupCredentials(apiConfig, function (error, credentials) {
|
||||
@@ -152,8 +139,8 @@ function copy(apiConfig, oldBackupId, newBackupId, callback) {
|
||||
|
||||
var params = {
|
||||
Bucket: apiConfig.bucket,
|
||||
Key: getBackupFilePath(apiConfig, newBackupId),
|
||||
CopySource: path.join(apiConfig.bucket, getBackupFilePath(apiConfig, oldBackupId))
|
||||
Key: newFilePath,
|
||||
CopySource: path.join(apiConfig.bucket, oldFilePath)
|
||||
};
|
||||
|
||||
var s3 = new AWS.S3(credentials);
|
||||
@@ -169,9 +156,9 @@ function copy(apiConfig, oldBackupId, newBackupId, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function removeMany(apiConfig, backupIds, callback) {
|
||||
function removeMany(apiConfig, filePaths, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert(Array.isArray(backupIds));
|
||||
assert(Array.isArray(filePaths));
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getBackupCredentials(apiConfig, function (error, credentials) {
|
||||
@@ -184,8 +171,8 @@ function removeMany(apiConfig, backupIds, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
backupIds.forEach(function (backupId) {
|
||||
params.Delete.Objects.push({ Key: getBackupFilePath(apiConfig, backupId) });
|
||||
filePaths.forEach(function (filePath) {
|
||||
params.Delete.Objects.push({ Key: filePath });
|
||||
});
|
||||
|
||||
var s3 = new AWS.S3(credentials);
|
||||
|
||||
Reference in New Issue
Block a user