Skip to content

Commit

Permalink
fix: Restore doesn't work when backup file is renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Nov 25, 2024
1 parent 392524e commit dc98ea2
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions app/client/packages/rts/src/ctl/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ async function restoreGitStorageArchive(
async function checkRestoreVersionCompatability(restoreContentsPath: string) {
const currentVersion = await utils.getCurrentAppsmithVersion();
const manifest_data = await fsPromises.readFile(
restoreContentsPath + "/manifest.json",
{ encoding: "utf8" },
path.join(restoreContentsPath, "manifest.json"),
"utf8",
);
const manifest_json = JSON.parse(manifest_data);
const restoreVersion = manifest_json["appsmithVersion"];
Expand All @@ -270,9 +270,9 @@ async function checkRestoreVersionCompatability(restoreContentsPath: string) {
"The Appsmith instance to be restored is not compatible with the current version.",
);
console.log(
'Please update your appsmith image to "index.docker.io/appsmith/appsmith-ce:' +
"Please update your appsmith image to 'index.docker.io/appsmith/appsmith-ce:" +
restoreVersion +
'" in the "docker-compose.yml" file\nand run the cmd: "docker-compose restart" ' +
"' in the 'docker-compose.yml' file\nand run the cmd: 'docker-compose restart' " +
"after the restore process is completed, to ensure the restored instance runs successfully.",
);
const confirm = readlineSync.question(
Expand Down Expand Up @@ -352,7 +352,7 @@ export async function run() {

const backupName = backupFileName.replace(/\.tar\.gz$/, "");
const restoreRootPath = await fsPromises.mkdtemp(os.tmpdir());
const restoreContentsPath = path.join(restoreRootPath, backupName);
const restoreContentsPath = await figureOutContentsPath(restoreRootPath);

await extractArchive(backupFilePath, restoreRootPath);
await checkRestoreVersionCompatability(restoreContentsPath);
Expand Down Expand Up @@ -390,3 +390,29 @@ export async function run() {
function isArchiveEncrypted(backupFilePath: string) {
return backupFilePath.endsWith(".enc");
}

async function figureOutContentsPath(root: string): Promise<string> {
const subfolders = await fsPromises.readdir(root, { withFileTypes: true });

for (const subfolder of subfolders) {
if (subfolder.isDirectory()) {
try {
// Try to find the `manifest.json` file.
await fsPromises.access(
path.join(root, subfolder.name, "manifest.json"),
);

return path.join(root, subfolder.name);
} catch (error) {
// If that fails, look for the MongoDB data archive, since some very old backups won't have `manifest.json`.
await fsPromises.access(
path.join(root, subfolder.name, "mongodb-data.gz"),
);

return path.join(root, subfolder.name);
}
}
}

throw new Error("Could not find the contents of the backup archive.");
}

0 comments on commit dc98ea2

Please sign in to comment.