Ghost/core/server/data/schema/backup.js
Katharina Irrgang bae0de6cd5 knex-migrator v2 (#7605)
* 🎨  knex-migrator reset

[ci skip]

*   add migration example

- hooks
- 1.0

[ci skip]

* 🛠  knex-migrator tarball

- remove when released

[ci skip]

* 🎨  jscs/jshint

* 🕵🏻 do not drop the database connection when running tests

- please read the comments in the commit

* 🔥  remove example migration

* 🛠  knex-migrator 0.1.0

* 🛠  knex-migrator 0.1.1

- fix a single test to ensure we catch the error

* 🛠  knex-migrator 0.1.2

* 🎨  make tests green

- added my keyword: kate-migrations
- i will go over all TODO's when removing the old migrations code

* 🛠  knex-migrator update

* 🛠  knex-migrator 0.2.0
2016-11-07 11:39:49 +00:00

45 lines
1.3 KiB
JavaScript

// # Backup Database
// Provides for backing up the database before making potentially destructive changes
var _ = require('lodash'),
fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
config = require('../../config'),
exporter = require('../export'),
writeExportFile,
backup;
writeExportFile = function writeExportFile(exportResult) {
var filename = path.resolve(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
*
* @param {{info: logger.info, warn: logger.warn}} [logger]
* @returns {Promise<*>}
*/
backup = function backup(logger) {
// If we get passed a function, use it to output notices, else don't do anything
logger = logger && _.isFunction(logger.info) ? logger : {info: _.noop};
logger.info('Creating database backup');
var props = {
data: exporter.doExport(),
filename: exporter.fileName()
};
return Promise.props(props)
.then(writeExportFile)
.then(function successMessage(filename) {
logger.info('Database backup written to: ' + filename);
});
};
module.exports = backup;