Skip to content

Commit

Permalink
Fix figuring out subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Nov 25, 2024
1 parent 61c893a commit 98f0ea2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/client/packages/rts/src/ctl/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,11 @@ export async function run() {

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

await extractArchive(backupFilePath, restoreRootPath);

const restoreContentsPath = await figureOutContentsPath(restoreRootPath);

await checkRestoreVersionCompatability(restoreContentsPath);

console.log(
Expand Down Expand Up @@ -394,6 +396,14 @@ function isArchiveEncrypted(backupFilePath: string) {
async function figureOutContentsPath(root: string): Promise<string> {
const subfolders = await fsPromises.readdir(root, { withFileTypes: true });

try {
// Check if the root itself contains the contents.
await fsPromises.access(path.join(root, "manifest.json"));
return root;
} catch (error) {
// Ignore
}

for (const subfolder of subfolders) {
if (subfolder.isDirectory()) {
try {
Expand All @@ -404,12 +414,18 @@ async function figureOutContentsPath(root: string): Promise<string> {

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`.
// Ignore
}

try {
// If that fails, look for the MongoDB data archive, since backups from v1.7.x and older won't have `manifest.json`.
await fsPromises.access(
path.join(root, subfolder.name, "mongodb-data.gz"),
);

return path.join(root, subfolder.name);
} catch (error) {
// Ignore
}
}
}
Expand Down

0 comments on commit 98f0ea2

Please sign in to comment.