diff --git a/src/apptask.js b/src/apptask.js index f0d118f3f..8452f253d 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -479,11 +479,10 @@ function backup(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); - var prefix = (new Date()).toISOString().replace(/[T.]/g, '-').replace(/[:Z]/g,''); async.series([ updateApp.bind(null, app, { installationProgress: '10, Backing up' }), - backups.backupApp.bind(null, app, app.manifest, prefix), + backups.backupApp.bind(null, app, app.manifest), // done! function (callback) { @@ -607,11 +606,9 @@ function update(app, callback) { function (next) { if (app.installationState === appdb.ISTATE_PENDING_FORCE_UPDATE) return next(null); - var prefix = (new Date()).toISOString().replace(/[T.]/g, '-').replace(/[:Z]/g,''); - async.series([ updateApp.bind(null, app, { installationProgress: '30, Backing up app' }), - backups.backupApp.bind(null, app, app.oldConfig.manifest, prefix) + backups.backupApp.bind(null, app, app.oldConfig.manifest) ], next); }, diff --git a/src/backups.js b/src/backups.js index e61d6ba72..6388c91f9 100644 --- a/src/backups.js +++ b/src/backups.js @@ -626,7 +626,7 @@ function uploadAppSnapshot(backupConfig, app, manifest, callback) { }); } -function backupApp(app, manifest, timestamp, callback) { +function backupAppWithTimestamp(app, manifest, timestamp, callback) { assert.strictEqual(typeof app, 'object'); assert(manifest && typeof manifest === 'object'); assert.strictEqual(typeof timestamp, 'string'); @@ -645,6 +645,22 @@ function backupApp(app, manifest, timestamp, callback) { }); } +function backupApp(app, manifest, callback) { + assert.strictEqual(typeof app, 'object'); + assert(manifest && typeof manifest === 'object'); + assert.strictEqual(typeof callback, 'function'); + + const timestamp = (new Date()).toISOString().replace(/[T.]/g, '-').replace(/[:Z]/g,''); + + progress.set(progress.BACKUP, 10, 'Backing up ' + (app.altDomain || config.appFqdn(app.location))); + + backupAppWithTimestamp(app, manifest, timestamp, function (error) { + progress.set(progress.BACKUP, 100, error ? error.message : ''); + + callback(error); + }); +} + // this function expects you to have a lock function backupBoxAndApps(auditSource, callback) { assert.strictEqual(typeof auditSource, 'object'); @@ -673,7 +689,7 @@ function backupBoxAndApps(auditSource, callback) { return iteratorCallback(null, app.lastBackupId); // just use the last backup } - backupApp(app, app.manifest, timestamp, function (error, backupId) { + backupAppWithTimestamp(app, app.manifest, timestamp, function (error, backupId) { if (error && error.reason !== BackupsError.BAD_STATE) { debugApp(app, 'Unable to backup', error); return iteratorCallback(error); diff --git a/src/cloudron.js b/src/cloudron.js index a648eba2a..ddfca89d9 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -420,7 +420,7 @@ function getConfig(callback) { fqdn: config.fqdn(), version: config.version(), update: updateChecker.getUpdateInfo(), - progress: progress.get(), + progress: progress.getAll(), isCustomDomain: config.isCustomDomain(), isDemo: config.isDemo(), developerMode: developerMode, diff --git a/src/progress.js b/src/progress.js index bb445d978..0252809ad 100644 --- a/src/progress.js +++ b/src/progress.js @@ -4,7 +4,7 @@ exports = module.exports = { set: set, setDetail: setDetail, clear: clear, - get: get, + getAll: getAll, UPDATE: 'update', BACKUP: 'backup', @@ -52,6 +52,11 @@ function clear(tag) { debug('clearing %s', tag); } -function get() { +function get(tag) { + return progress[tag]; +} + +function getAll() { return progress; } + diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index c6506b6eb..ba1c11e0e 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -142,7 +142,7 @@ function getStatus(req, res, next) { } function getProgress(req, res, next) { - return next(new HttpSuccess(200, progress.get())); + return next(new HttpSuccess(200, progress.getAll())); } function reboot(req, res, next) {