-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsample_restore.js
35 lines (30 loc) · 1.06 KB
/
sample_restore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// in option to show the executed "command", add env variable like this
// export MT_SHOW_COMMAND=true
// node-mongotools users must use this line
// import { MongoTools, MTOptions, MTCommand } from "node-mongotools";
// import from inside project
import {MongoTools, MTCommand} from "../lib/mt.js";
async function restore(uri, dumpFile) {
const mt = new MongoTools();
const mtc = new MTCommand();// to reuse log methods
// mongorestore
const restoreResult = await mt.mongorestore({
uri,
dumpFile,
dropBeforeRestore: true,
deleteDumpAfterRestore: true
})
.catch(mtc.logError.bind(mtc));
if (restoreResult === undefined) {// error case
process.exit(1);
}
mtc.logSuccess(restoreResult);
}
// take first command line argument
if (process.argv.slice(2).length !== 1) {
console.log("please provide backup full filename as argument");
process.exit(1);
}
var backupFilePath = process.argv.slice(2)[0];
const uri = process.env.MY_MONGO_URI
restore(uri, backupFilePath);