|
|
@@ -365,16 +365,12 @@ exports.getSave = handleError(async (req, res) => {
|
|
|
})
|
|
|
|
|
|
exports.backup = handleError(async (req, res) => {
|
|
|
- let db = 'ptb-db'
|
|
|
- const baseUrl = coba.decrypt(process.env.W8A1C)
|
|
|
- if (baseUrl.includes('dev')) db = 'ptb-db-dev'
|
|
|
+ const mongoUrl = coba.decrypt(process.env.MYDSY)
|
|
|
+ let cmd = `mongodump --uri ${mongoUrl} -o backup/${moment().format('YYYY-MM-DD')}`
|
|
|
|
|
|
- let cmd = `mongodump -d ${db} -o backup/${moment().format('YYYY-MM-DD')}`
|
|
|
-
|
|
|
- const akun = coba.decrypt(process.env.MYDSY).match(/\/\/(.*?)@/i)
|
|
|
+ const akun = mongoUrl.match(/\/\/(.*?)@/i)
|
|
|
if (akun?.length) {
|
|
|
- const [username, password] = akun[1].split(':')
|
|
|
- cmd += ` -u ${username} -p ${password} --authenticationDatabase admin`
|
|
|
+ cmd += ` --authenticationDatabase admin`
|
|
|
}
|
|
|
|
|
|
childProcess.execSync(cmd)
|
|
|
@@ -390,16 +386,13 @@ exports.restore = handleError(async (req, res) => {
|
|
|
if (!isValid) return
|
|
|
|
|
|
const { tanggal } = req.query
|
|
|
- let db = 'ptb-db'
|
|
|
- const baseUrl = coba.decrypt(process.env.W8A1C)
|
|
|
- if (baseUrl.includes('dev')) db = 'ptb-db-dev'
|
|
|
-
|
|
|
- let cmd = `mongorestore -d ${db}`
|
|
|
+ const mongoUrl = coba.decrypt(process.env.MYDSY)
|
|
|
+ let cmd = `mongorestore --uri ${mongoUrl}`
|
|
|
|
|
|
- const akun = coba.decrypt(process.env.MYDSY).match(/\/\/(.*?)@/i)
|
|
|
+ const akun = mongoUrl.match(/\/\/(.*?)@/i)
|
|
|
if (akun?.length) {
|
|
|
const [username, password] = akun[1].split(':')
|
|
|
- cmd += ` -u ${username} -p ${password} --authenticationDatabase admin`
|
|
|
+ cmd += ` --authenticationDatabase admin`
|
|
|
}
|
|
|
cmd += ` backup/${tanggal}`
|
|
|
|