Skip to content

Commit

Permalink
fix: failing backup and restore appsmithctl
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapaprasanna committed Jul 24, 2024
1 parent 404e6e6 commit bb0509f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions deploy/docker/fs/opt/appsmith/utils/bin/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function getEncryptionPasswordFromUser(){

async function exportDatabase(destFolder) {
console.log('Exporting database');
await executeMongoDumpCMD(destFolder, process.env.APPSMITH_DB_URL)
await executeMongoDumpCMD(destFolder, utils.getDburl())
console.log('Exporting database done.');
}

Expand All @@ -141,7 +141,7 @@ async function createGitStorageArchive(destFolder) {

async function createManifestFile(path) {
const version = await utils.getCurrentAppsmithVersion()
const manifest_data = { "appsmithVersion": version, "dbName": utils.getDatabaseNameFromMongoURI(process.env.APPSMITH_DB_URL) }
const manifest_data = { "appsmithVersion": version, "dbName": utils.getDatabaseNameFromMongoURI(utils.getDburl()) }
await fsPromises.writeFile(path + '/manifest.json', JSON.stringify(manifest_data));
}

Expand Down Expand Up @@ -259,4 +259,4 @@ module.exports = {
removeOldBackups,
getEncryptionPasswordFromUser,
encryptBackupArchive,
};
};
7 changes: 5 additions & 2 deletions deploy/docker/fs/opt/appsmith/utils/bin/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const APPSMITHCTL_LOG_PATH = "/appsmith-stacks/logs/appsmithctl"

const LAST_ERROR_MAIL_TS = "/appsmith-stacks/data/backup/last-error-mail-ts"

const ENV_PATH = "/appsmith-stacks/configuration/docker.env"

const MIN_REQUIRED_DISK_SPACE_IN_BYTES = 2147483648 // 2GB

const DURATION_BETWEEN_BACKUP_ERROR_MAILS_IN_MILLI_SEC = 21600000 // 6 hrs
Expand All @@ -23,5 +25,6 @@ module.exports = {
APPSMITHCTL_LOG_PATH,
MIN_REQUIRED_DISK_SPACE_IN_BYTES,
DURATION_BETWEEN_BACKUP_ERROR_MAILS_IN_MILLI_SEC,
APPSMITH_DEFAULT_BACKUP_ARCHIVE_LIMIT
}
APPSMITH_DEFAULT_BACKUP_ARCHIVE_LIMIT,
ENV_PATH
}
23 changes: 22 additions & 1 deletion deploy/docker/fs/opt/appsmith/utils/bin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const shell = require("shelljs");
const fsPromises = require("fs/promises");
const Constants = require("./constants");
const childProcess = require("child_process");
const fs = require('node:fs');
const { ConnectionString } = require("mongodb-connection-string-url");

function showHelp() {
Expand Down Expand Up @@ -31,6 +32,25 @@ function start(apps) {
console.log("Started " + appsStr);
}


function getDburl() {
try {
let env_array = fs.readFileSync(Constants.ENV_PATH, 'utf8').toString().split("\n");
for(i in env_array) {
if (env_array[i].startsWith("APPSMITH_MONGODB_URI") || env_array[i].startsWith("APPSMITH_DB_URL")) {
var dbUrl = env_array[i].toString().split("=")[1];
}
}
} catch (err) {
console.error(err);
}
let dbEnvUrl = process.env.APPSMITH_DB_URL || process.env.APPSMITH_MONGO_DB_URI;
if (dbEnvUrl != "undefined"){
var dbUrl = dbEnvUrl;
}
return dbUrl;
}

function execCommand(cmd, options) {
return new Promise((resolve, reject) => {
let isPromiseDone = false;
Expand Down Expand Up @@ -174,4 +194,5 @@ module.exports = {
preprocessMongoDBURI,
execCommandSilent,
getDatabaseNameFromMongoURI,
};
getDburl
};

0 comments on commit bb0509f

Please sign in to comment.