diff --git a/ghost/settings-path-manager/lib/settings-path-manager.js b/ghost/settings-path-manager/lib/settings-path-manager.js index 9064c735f0..49771ceba5 100644 --- a/ghost/settings-path-manager/lib/settings-path-manager.js +++ b/ghost/settings-path-manager/lib/settings-path-manager.js @@ -1,5 +1,6 @@ const path = require('path'); const tpl = require('@tryghost/tpl'); +const format = require('date-fns/format'); const {IncorrectUsageError} = require('@tryghost/errors'); const messages = { @@ -35,6 +36,12 @@ class SettingsPathManager { const settingsFolder = this.defaultPath; return path.join(settingsFolder, `${this.filename}.${this.defaultExtension}`); } + + getBackupFilePath() { + const settingsFolder = this.defaultPath; + const dateStamp = format(new Date(), 'yyyy-MM-dd-HH-mm-ss'); + return path.join(settingsFolder, `${this.filename}-${dateStamp}.${this.defaultExtension}`); + } } module.exports = SettingsPathManager; diff --git a/ghost/settings-path-manager/package.json b/ghost/settings-path-manager/package.json index ef2bdf4fd8..3e8d71cf15 100644 --- a/ghost/settings-path-manager/package.json +++ b/ghost/settings-path-manager/package.json @@ -25,6 +25,7 @@ "sinon": "11.1.2" }, "dependencies": { + "date-fns": "^2.24.0", "tpl": "^0.3.0" } } diff --git a/ghost/settings-path-manager/test/settings-path-manager.test.js b/ghost/settings-path-manager/test/settings-path-manager.test.js index d7134fd38a..efda34305c 100644 --- a/ghost/settings-path-manager/test/settings-path-manager.test.js +++ b/ghost/settings-path-manager/test/settings-path-manager.test.js @@ -54,4 +54,18 @@ describe('Settings Path Manager', function () { path.should.equal('/content/data/redirects.json'); }); }); + + describe('getBackupFilePath', function () { + it('returns a path to store a backup', function (){ + const settingsPathManager = new SettingsPathManager({ + paths: ['/content/data', '/content/settings'], + type: 'routes', + extensions: ['yaml'] + }); + + const path = settingsPathManager.getBackupFilePath(); + + path.should.match(/\/content\/data\/routes-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}.yaml/); + }); + }); });