Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Restore doesn't work when backup file is renamed #37666

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/client/packages/rts/src/ctl/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ export async function run() {

try {
// PRE-BACKUP
console.log("Available free space at /appsmith-stacks");
const availSpaceInBytes: number =
await getAvailableBackupSpaceInBytes("/appsmith-stacks");

console.log("\n");

checkAvailableBackupSpace(availSpaceInBytes);

if (
Expand Down
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.");
}
Loading