This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·64 lines (50 loc) · 1.47 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const pkginfo = require('./package.json');
const program = require('commander');
let source;
let destination;
let regex;
program
.version(pkginfo.version)
.option('-v, --verbose', 'enable debug messages')
.option('-O, --overwrite', 'erase all documents in an index before copying')
.option('-R, --remove', 'remove indexes not on source')
.option('-y, --yes', 'confirm')
.arguments('<source> <destination> [regex of indexes to copy]')
.usage('[options] <source> <destination> [regex of indexes to copy]')
.action((cmdSource, cmdDestination, cmdRegex) => {
source = cmdSource;
destination = cmdDestination;
regex = cmdRegex;
});
program.on('--help', () => {
console.log(' Examples:');
console.log('');
console.log(' $ migrate-elasticsearch 10.0.10.40:9200 10.0.11.40:9200');
console.log(' $ migrate-elasticsearch 10.0.10.40:9200 10.0.11.40:9200 daily\..*');
console.log('');
});
program.parse(process.argv);
if(!source) {
program.help();
}
if(program.verbose) {
process.env.DEBUG="*";
}
const elasticsearch = require('./lib/elasticsearch');
if(program.overwrite) {
elasticsearch.flags.overwrite = true;
}
if(program.remove) {
elasticsearch.flags.removeExtra = true;
}
if(program.yes) {
elasticsearch.flags.yes = true;
}
if(!source.startsWith('http')) {
source = `http://${source}`;
}
if(!destination.startsWith('http')) {
destination = `http://${destination}`;
}
elasticsearch.migrate(source, destination, regex);