0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/data/db/backup.js
Katharina Irrgang c9e3f8b180 🐛 Fix ghost update with migrations (#8810)
no issue

- if you backup your database and you are in the middle of a transaction, the transaction was not fully forwarded
- we were running into a pool error in knex
2017-08-01 17:27:13 +04: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'),
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(options) {
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) {
logging.info('Database backup written to: ' + filename);
});
};
module.exports = backup;