Ghost/core/server/data/db/backup.js
kirrg001 529bec8089 Renamed core/server/data/export to core/server/data/exporter
no issue

- i'vejust renamed the folder
- it makes more sense
  - data/importer
  - data/exporter
2018-08-16 12:13:24 +02:00

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'),
urlService = require('../../services/url'),
exporter = require('../exporter'),
writeExportFile,
backup;
writeExportFile = function writeExportFile(exportResult) {
var filename = path.resolve(urlService.utils.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;