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

chore: Fix typing in ctl backup and restore #37663

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add types to restore.ts as well
  • Loading branch information
sharat87 committed Nov 23, 2024
commit 032df64d0740057c7da9672e7b188d666694c8a2
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();
sharat87 marked this conversation as resolved.
Show resolved Hide resolved
} 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");
}
Loading