0
Fork 0
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:
Steve Larson 2024-02-01 12:09:41 -06:00 committed by GitHub
parent 1a3e7cbd7d
commit 2c166582fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View file

@ -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);

View file

@ -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;

View file

@ -228,5 +228,6 @@
},
"bulkEmail": {
"batchSize": 1000
}
},
"disableJSBackups": false
}

View file

@ -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);
});
});