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

feat: add postgres data backup to appsmith ctl #37837

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
43 changes: 43 additions & 0 deletions app/client/packages/rts/src/ctl/export_db_pg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fsPromises from "fs/promises";
import * as Constants from "./constants";
import * as utils from "./utils";
import { writeDataFromMongoToJsonlFiles } from './move-to-postgres.mjs';


export async function exportDatabase() {
const dbUrl = utils.getDburl();
try {
await writeDataFromMongoToJsonlFiles(dbUrl);
console.log('MongoDB data exported successfully.');
} catch (error) {
console.error('Error exporting MongoDB data:', error);
}
}

export async function run() {
let errorCode = 0;

await utils.ensureSupervisorIsRunning();

try {
console.log("stop backend & rts application before export database");
await utils.stop(["backend", "rts"]);
await exportDatabase();
console.log("start backend & rts application after export database");
console.log();
console.log("\x1b[0;33m++++++++++++++++++++ NOTE ++++++++++++++++++++");
console.log();
console.log(
"Please remember to also copy APPSMITH_ENCRYPTION_SALT and APPSMITH_ENCRYPTION_PASSWORD variables from the docker.env file to the target instance where you intend to import this database dump.",
);
console.log();
console.log("++++++++++++++++++++++++++++++++++++++++++++++\x1b[0m");
console.log();
} catch (err) {
console.log(err);
errorCode = 1;
} finally {
await utils.start(["backend", "rts"]);
process.exit(errorCode);
}
}
Comment on lines +17 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add signal handlers and improve process management

The function should handle interruption signals and ensure proper cleanup.

 export async function run() {
   let errorCode = 0;
+  const cleanup = async () => {
+    try {
+      await utils.start(["backend", "rts"]);
+    } finally {
+      process.exit(errorCode);
+    }
+  };
+
+  process.on('SIGINT', cleanup);
+  process.on('SIGTERM', cleanup);

   await utils.ensureSupervisorIsRunning();

Committable suggestion skipped: line range outside the PR's diff.

5 changes: 5 additions & 0 deletions app/client/packages/rts/src/ctl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import process from "process";
import { showHelp } from "./utils";
import * as export_db from "./export_db";
import * as import_db from "./import_db";
import * as export_db_pg from "./export_db_pg";
import * as backup from "./backup";
import * as restore from "./restore";
import * as check_replica_set from "./check_replica_set";
Expand Down Expand Up @@ -34,6 +35,10 @@ if (["export-db", "export_db", "ex"].includes(command)) {
console.log("Exporting database");
export_db.run();
console.log("Export database done");
} else if (["export-mongo-to-pg"].includes(command)) {
console.log("Exporting data dump for Postgres migration");
export_db_pg.run();
console.log("Exporting data dump for Postgres migration done");
} else if (["import-db", "import_db", "im"].includes(command)) {
console.log("Importing database");
// Get Force option flag to run import DB immediately
Expand Down
Loading
Loading