Skip to content

Commit

Permalink
fix(backup): Ensure the backup is up-to-date
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ErisDS committed May 19, 2022
1 parent 6a38ad3 commit 8f31625
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/tasks/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const {ProcessError} = require('../errors');
const {exportTask} = require('./import');

module.exports = async function (ui, instance) {
const datetime = require('moment')().format('YYYY-MM-DD-HH-mm-ss');
const backupSuffix = `from-v${instance.version}-on-${datetime}`;

// First we need to export the content into a JSON file & members into a CSV file
const contentExportPath = 'data/backup.json';
const membersExportPath = 'data/members.csv';
const contentExportPath = `data/content-${backupSuffix}.json`;
const membersExportPath = `data/members-${backupSuffix}.csv`;

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

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

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

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

0 comments on commit 8f31625

Please sign in to comment.