provision: download mail backup during restore

This commit is contained in:
Girish Ramakrishnan
2021-09-26 22:55:23 -07:00
parent 7ea9252059
commit d390495608

View File

@@ -69,6 +69,8 @@ exports = module.exports = {
};
const assert = require('assert'),
backups = require('./backups.js'),
backuptask = require('./backuptask.js'),
BoxError = require('./boxerror.js'),
cloudron = require('./cloudron.js'),
constants = require('./constants.js'),
@@ -749,6 +751,18 @@ async function restartMail() {
async function startMail(existingInfra) {
assert.strictEqual(typeof existingInfra, 'object');
if (existingInfra.version === 'none') {
const [error, results] = await safe(backups.getByIdentifierAndStatePaged(backups.BACKUP_IDENTIFIER_MAIL, backups.BACKUP_STATE_NORMAL, 1, 1));
if (error || results.length == 0) {
debug('startMail: could not find backup to restore', error, results);
} else {
debug(`startMail: downloading backup ${results[0].id}`);
const restoreConfig = { backupId: results[0].id, backupFormat: results[0].format };
// have to wait for download before starting mail container because we download as non-root user
await backuptask.downloadMail(restoreConfig, (message) => debug(`startMail: ${message}`));
}
}
await restartMail();
}