Skip to content

Commit 94a320e

Browse files
committed
fix(backup): Ensure the backup is up-to-date
refs: TryGhost/Toolbox#334 refs: TryGhost#468 - if the backup command is run multiple times, and the latter runs fail to export, the backup files would be old - this ensures that the backup files all belong together - also renames backup to content
1 parent 197ccb3 commit 94a320e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/tasks/backup.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ const {ProcessError} = require('../errors');
88
const {exportTask} = require('./import');
99

1010
module.exports = async function (ui, instance) {
11+
const datetime = require('moment')().format('YYYY-MM-DD-HH-mm-ss');
12+
const backupSuffix = `from-v${instance.version}-on-${datetime}`;
13+
1114
// First we need to export the content into a JSON file & members into a CSV file
12-
const contentExportPath = 'data/backup.json';
13-
const membersExportPath = 'data/members.csv';
15+
const contentExportPath = `data/content-${backupSuffix}.json`;
16+
const membersExportPath = `data/members-${backupSuffix}.csv`;
1417

1518
await exportTask(ui, instance, path.join(instance.dir, 'content/', contentExportPath), path.join(instance.dir, 'content/', membersExportPath));
1619

@@ -34,8 +37,7 @@ module.exports = async function (ui, instance) {
3437
}
3538

3639
// Finally we zip everything up into a nice little package
37-
const datetime = require('moment')().format('YYYY-MM-DD-HH-mm-ss');
38-
const zipPath = path.join(process.cwd(), `backup-from-v${instance.version}-on-${datetime}.zip`);
40+
const zipPath = path.join(process.cwd(), `backup-${backupSuffix}.zip`);
3941

4042
try {
4143
execa.shellSync(`zip -r ${zipPath} ${contentExportPath} ${membersExportPath} files/ images/ media/ settings/ themes/`, {

0 commit comments

Comments
 (0)