Skip to content

Commit

Permalink
added functionality to restore to main db
Browse files Browse the repository at this point in the history
  • Loading branch information
mirmahathir1 committed Aug 4, 2021
1 parent 2a7bd26 commit 59ab5b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions badhan.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ yargs.command({
describe: 'The backup having the specified timestamp will be restored',
demandOption: true,
type: 'number'
},
production: {
describe: 'If true, then the backup will be restored to the production database',
type: 'boolean',
default: false,
}
},
handler: controllers.restoreController
Expand Down
9 changes: 8 additions & 1 deletion controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ const getBackupList = async ()=>{
const restoreController = async (argv) => {
console.log("restore command initiated");
console.log("time: ",argv.time);
console.log("restore to production: ",argv.production);

let mongoURI = process.env.MONGODB_URI_TEST;

if(argv.production===true){
mongoURI = process.env.MONGODB_URI_PROD;
}

console.log("fetching backups from cloud...")
let backupList = await getBackupList();
Expand All @@ -140,7 +147,7 @@ const restoreController = async (argv) => {
let backupProcess = spawn('./mongorestore', [
'--drop',
'--dir=backup/'+argv.time+'/Badhan',
process.env.MONGODB_URI_TEST
mongoURI
]);

backupProcess.on('exit', async (code, signal) => {
Expand Down

0 comments on commit 59ab5b8

Please sign in to comment.