mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
0424c6675c
refs #7489 The require path for the db backup was wrong. The before hook could not execute db backup. Furthermore, i have replaced the logging in the backup script.
41 lines
1.2 KiB
JavaScript
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'),
|
|
logging = require('../../logging'),
|
|
utils = require('../../utils'),
|
|
exporter = require('../export'),
|
|
|
|
writeExportFile,
|
|
backup;
|
|
|
|
writeExportFile = function writeExportFile(exportResult) {
|
|
var filename = path.resolve(utils.url.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() {
|
|
logging.info('Creating database backup');
|
|
|
|
var props = {
|
|
data: exporter.doExport(),
|
|
filename: exporter.fileName()
|
|
};
|
|
|
|
return Promise.props(props)
|
|
.then(writeExportFile)
|
|
.then(function successMessage(filename) {
|
|
logging.info('Database backup written to: ' + filename);
|
|
});
|
|
};
|
|
|
|
module.exports = backup;
|