Skip to content

Commit

Permalink
Add types to restore.ts as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sharat87 committed Nov 23, 2024
1 parent 9a24517 commit 032df64
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions app/client/packages/rts/src/ctl/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function getBackupFileName() {
}
}

async function decryptArchive(encryptedFilePath, backupFilePath) {
async function decryptArchive(encryptedFilePath: string, backupFilePath: string) {
console.log("Enter the password to decrypt the backup archive:");

for (const attempt of [1, 2, 3]) {
Expand All @@ -75,7 +75,7 @@ async function decryptArchive(encryptedFilePath, backupFilePath) {
"-aes-256-cbc",
"-pbkdf2",
"-iter",
100000,
"100000",
"-in",
encryptedFilePath,
"-out",
Expand All @@ -93,7 +93,7 @@ async function decryptArchive(encryptedFilePath, backupFilePath) {
return false;
}

async function extractArchive(backupFilePath, restoreRootPath) {
async function extractArchive(backupFilePath: string, restoreRootPath: string) {
console.log("Extracting the Appsmith backup archive at " + backupFilePath);
await utils.execCommand([
"tar",
Expand All @@ -105,7 +105,7 @@ async function extractArchive(backupFilePath, restoreRootPath) {
console.log("Extracting the backup archive completed");
}

async function restoreDatabase(restoreContentsPath, dbUrl) {
async function restoreDatabase(restoreContentsPath: string, dbUrl: string) {
console.log("Restoring database...");
const cmd = [
"mongorestore",
Expand Down Expand Up @@ -136,9 +136,9 @@ async function restoreDatabase(restoreContentsPath, dbUrl) {
}

async function restoreDockerEnvFile(
restoreContentsPath,
backupName,
overwriteEncryptionKeys,
restoreContentsPath: string,
backupName: string,
overwriteEncryptionKeys: boolean,
) {
console.log("Restoring docker environment file");
const dockerEnvFile = "/appsmith-stacks/configuration/docker.env";
Expand Down Expand Up @@ -227,9 +227,8 @@ async function restoreDockerEnvFile(
console.log("Restoring docker environment file completed");
}

async function restoreGitStorageArchive(restoreContentsPath, backupName) {
async function restoreGitStorageArchive(restoreContentsPath: string, backupName: string) {
console.log("Restoring git-storage archive");
// TODO: Consider APPSMITH_GIT_ROOT env for later iterations
const gitRoot = "/appsmith-stacks/git-storage";

await utils.execCommand(["mv", gitRoot, gitRoot + "-" + backupName]);
Expand All @@ -241,7 +240,7 @@ async function restoreGitStorageArchive(restoreContentsPath, backupName) {
console.log("Restoring git-storage archive completed");
}

async function checkRestoreVersionCompatability(restoreContentsPath) {
async function checkRestoreVersionCompatability(restoreContentsPath: string) {
const currentVersion = await utils.getCurrentAppsmithVersion();
const manifest_data = await fsPromises.readFile(
restoreContentsPath + "/manifest.json",
Expand Down Expand Up @@ -280,7 +279,7 @@ async function checkRestoreVersionCompatability(restoreContentsPath) {
}
}

async function getBackupDatabaseName(restoreContentsPath) {
async function getBackupDatabaseName(restoreContentsPath: string) {
let db_name = "appsmith";

if (command_args.includes("--backup-db-name")) {
Expand All @@ -307,18 +306,17 @@ async function getBackupDatabaseName(restoreContentsPath) {
}

export async function run() {
let errorCode = 0;
let cleanupArchive = false;
let overwriteEncryptionKeys = true;
let backupFilePath;
let backupFilePath: string;

await utils.ensureSupervisorIsRunning();

try {
let backupFileName = await getBackupFileName();

if (backupFileName == null) {
process.exit(errorCode);
process.exit();
} else {
backupFilePath = path.join(Constants.BACKUP_PATH, backupFileName);

Expand All @@ -342,7 +340,7 @@ export async function run() {
"You have entered the incorrect password multiple times. Aborting the restore process.",
);
await fsPromises.rm(backupFilePath, { force: true });
process.exit(errorCode);
process.exit();
}
}

Expand Down Expand Up @@ -372,17 +370,17 @@ export async function run() {
}
} catch (err) {
console.log(err);
errorCode = 1;
process.exitCode = 1;
} finally {
if (cleanupArchive) {
await fsPromises.rm(backupFilePath, { force: true });
}

await utils.start(["backend", "rts"]);
process.exit(errorCode);
process.exit();
}
}

function isArchiveEncrypted(backupFilePath) {
function isArchiveEncrypted(backupFilePath: string) {
return backupFilePath.endsWith(".enc");
}

0 comments on commit 032df64

Please sign in to comment.