mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
abda6e6338
closes #10773 - The refactoring is a substitute for `urlService.utils` used previously throughout the codebase and now extracted into the separate module in Ghost-SDK - Added url-utils stubbing utility for test suites - Some tests had to be refactored to avoid double mocks (when url's are being reset inside of rested 'describe' groups)
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
// # Backup Database
|
|
// Provides for backing up the database before making potentially destructive changes
|
|
var fs = require('fs-extra'),
|
|
path = require('path'),
|
|
Promise = require('bluebird'),
|
|
config = require('../../config'),
|
|
common = require('../../lib/common'),
|
|
urlUtils = require('../../lib/url-utils'),
|
|
exporter = require('../exporter'),
|
|
|
|
writeExportFile,
|
|
backup;
|
|
|
|
writeExportFile = function writeExportFile(exportResult) {
|
|
var filename = path.resolve(urlUtils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
|
|
|
|
return fs.writeFile(filename, JSON.stringify(exportResult.data)).return(filename);
|
|
};
|
|
|
|
/**
|
|
* ## Backup
|
|
* does an export, and stores this in a local file
|
|
* @returns {Promise<*>}
|
|
*/
|
|
backup = function backup(options) {
|
|
common.logging.info('Creating database backup');
|
|
options = options || {};
|
|
|
|
var props = {
|
|
data: exporter.doExport(options),
|
|
filename: exporter.fileName(options)
|
|
};
|
|
|
|
return Promise.props(props)
|
|
.then(writeExportFile)
|
|
.then(function successMessage(filename) {
|
|
common.logging.info('Database backup written to: ' + filename);
|
|
return filename;
|
|
});
|
|
};
|
|
|
|
module.exports = backup;
|