Skip to content

Commit

Permalink
Make project backup script auth-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Oct 7, 2024
1 parent 9440327 commit 463c6b9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions backup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import path from "path";
import net from "net";

// Expected arguments: first arg is project ID (5dbf805650b51914727e06c4) or URL (http://localhost:8080/app/lexicon/5dbf805650b51914727e06c4)
// Second arg is "qa" or "staging" to copy from staging, "live" or "prod" or "production" to copy from production
// Second arg is the mongodb password of the selected environment
// Third arg is "qa" or "staging" to copy from staging, "live" or "prod" or "production" to copy from production
// NOTE: You must edit the context names below if they don't match the context names you have (see `kubectl config get-contexts` output)

// ===== EDIT THIS =====
Expand Down Expand Up @@ -107,8 +108,10 @@ if (!contexts.includes(prodContext)) {

// Process args

if (process.argv.length < 3) {
console.warn("Please pass project ID or URL as argument, e.g. node backup.mjs 5dbf805650b51914727e06c4");
if (process.argv.length < 4) {
console.warn(
"Please pass project ID or URL and MongoDB password as arguments, e.g. node backup.mjs 5dbf805650b51914727e06c4 pass",
);
process.exit(2);
}

Expand All @@ -128,8 +131,8 @@ if (URL.canParse(arg)) {
let context = defaultContext;
let contextName = defaultContextName;

if (process.argv.length > 3) {
const env = process.argv[3];
if (process.argv.length > 4) {
const env = process.argv[4];
switch (env) {
case "qa":
context = stagingContext;
Expand Down Expand Up @@ -209,7 +212,8 @@ console.warn("If that doesn't look right, hit Ctrl+C NOW");
await portForwardingPromise;
console.warn("Port forwarding is ready. Setting up remote Mongo connection...");

const remoteConnStr = `mongodb://localhost:${remoteMongoPort}`;
const pass = process.argv[3];
const remoteConnStr = `mongodb://lexbox:${pass}@localhost:${remoteMongoPort}`;
remoteConn = await MongoClient.connect(remoteConnStr);

console.warn("Remote Mongo connection established. Fetching project record...");
Expand Down

0 comments on commit 463c6b9

Please sign in to comment.