0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/server/data/db/backup.js
kirrg001 6f6c8f4521 Import lib/common only
refs #9178

- avoid importing 4 modules (logging, errors, events and i18n)
- simply require common in each file
2017-12-12 10:28:13 +01:00

41 lines
1.2 KiB
JavaScript

// # Backup Database
// Provides for backing up the database before making potentially destructive changes
var fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
config = require('../../config'),
common = require('../../lib/common'),
urlService = require('../../services/url'),
exporter = require('../export'),
writeExportFile,
backup;
writeExportFile = function writeExportFile(exportResult) {
var filename = path.resolve(urlService.utils.urlJoin(config.get('paths').contentPath, 'data', exportResult.filename));
return Promise.promisify(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);
});
};
module.exports = backup;