mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
Added config option to disable db backups (#19614)
refs https://linear.app/tryghost/issue/ENG-600 - users need an option so they can perform actions like delete users without blowing up Ghost as large dbs can OOM node
This commit is contained in:
parent
1a3e7cbd7d
commit
2c166582fd
4 changed files with 28 additions and 4 deletions
|
@ -42,9 +42,15 @@ const readBackup = async (filename) => {
|
|||
* Does an export, and stores this in a local file
|
||||
*
|
||||
* @param {Object} options
|
||||
* @returns {Promise<String>}
|
||||
* @returns {Promise<String> | null}
|
||||
*/
|
||||
const backup = async function backup(options = {}) {
|
||||
// do not create backup if disabled in config (this is intended for large customers who will OOM node)
|
||||
if (config.get('disableJSBackups')) {
|
||||
logging.info('Database backup is disabled in Ghost config');
|
||||
return null;
|
||||
}
|
||||
|
||||
logging.info('Creating database backup');
|
||||
|
||||
const filename = await exporter.fileName(options);
|
||||
|
|
|
@ -148,9 +148,13 @@ class Users {
|
|||
* @returns
|
||||
*/
|
||||
async destroyUser(frameOptions) {
|
||||
let filename = null;
|
||||
const backupPath = await this.dbBackup.backup();
|
||||
const parsedFileName = path.parse(backupPath);
|
||||
const filename = `${parsedFileName.name}${parsedFileName.ext}`;
|
||||
|
||||
if (backupPath) {
|
||||
const parsedFileName = path.parse(backupPath);
|
||||
filename = `${parsedFileName.name}${parsedFileName.ext}`;
|
||||
}
|
||||
|
||||
return this.models.Base.transaction(async (t) => {
|
||||
frameOptions.transacting = t;
|
||||
|
|
|
@ -228,5 +228,6 @@
|
|||
},
|
||||
"bulkEmail": {
|
||||
"batchSize": 1000
|
||||
}
|
||||
},
|
||||
"disableJSBackups": false
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ const fs = require('fs-extra');
|
|||
const models = require('../../../../../core/server/models');
|
||||
const exporter = require('../../../../../core/server/data/exporter');
|
||||
const dbBackup = require('../../../../../core/server/data/db/backup');
|
||||
const configUtils = require('../../../../utils/configUtils');
|
||||
|
||||
describe('Backup', function () {
|
||||
let exportStub;
|
||||
|
@ -33,4 +34,16 @@ describe('Backup', function () {
|
|||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('should not create a backup JSON file if disabled', function (done) {
|
||||
configUtils.set('disableJSBackups', true);
|
||||
|
||||
dbBackup.backup().then(function () {
|
||||
exportStub.called.should.be.false();
|
||||
filenameStub.called.should.be.false();
|
||||
fsStub.called.should.be.false();
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue