Skip to content

Commit 69779bf

Browse files
committed
fix: broken mongodump
1 parent b68008e commit 69779bf

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

api/src/dump.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ export const dump = async (dumpKey: string, _name?: string) => {
5252
await client.close()
5353
for (const db of dbs.databases.map(db => db.name).filter(db => !config.mongo.ignoreDBs.includes(db))) {
5454
debug(`work on db ${db}`)
55-
debug(`create tmp file ${config.tmpdir}`)
5655
const tmpFile = await tmp.file({ dir: config.tmpdir })
57-
debug(`created tmp file ${tmpFile.path}`)
5856
const tmpPath = tmpFile.path
59-
let cmd = `mongodump --uri ${config.mongo.url}/${db}?readPreference=${config.mongo.readPreference} --gzip --archive=${tmpPath}`
57+
const mongoUrl = new URL(config.mongo.url)
58+
mongoUrl.searchParams.set('readPreference', config.mongo.readPreference)
59+
mongoUrl.pathname = '/' + db
60+
let cmd = `mongodump --uri ${mongoUrl.href} --gzip --archive=${tmpPath}`
6061
if (config.mongo.dumpParams && config.mongo.dumpParams[db]) {
6162
cmd += ` ${config.mongo.dumpParams[db]}`
6263
}

api/src/utils/exec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { spawn, type SpawnOptions } from 'node:child_process'
2+
import debugModule from 'debug'
3+
4+
const debug = debugModule('exec')
25

36
export async function exec (cmd: string, opts: SpawnOptions = {}) {
4-
console.log('exec', cmd, opts)
7+
debug('exec command', cmd, opts)
58
return new Promise<void>((resolve, reject) => {
69
const childProcess = spawn(cmd, { shell: true, stdio: 'inherit', ...opts })
710
childProcess.on('error', reject)

0 commit comments

Comments
 (0)