1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | 'use strict';
|
16 |
|
17 | const error = require('../includes/error.js');
|
18 | const cliutils = require('../includes/cliutils.js');
|
19 | const couchbackup = require('../app.js');
|
20 | const parser = require('../includes/parser.js');
|
21 | const debug = require('debug');
|
22 | const restoreDebug = debug('couchbackup:restore');
|
23 | const restoreBatchDebug = debug('couchbackup:restore:batch');
|
24 |
|
25 | restoreDebug.enabled = true;
|
26 |
|
27 | const program = parser.parseRestoreArgs();
|
28 | const databaseUrl = cliutils.databaseUrl(program.url, program.db);
|
29 | const opts = {
|
30 | bufferSize: program.bufferSize,
|
31 | parallelism: program.parallelism,
|
32 | requestTimeout: program.requestTimeout,
|
33 | iamApiKey: program.iamApiKey,
|
34 | iamTokenUrl: program.iamTokenUrl
|
35 | };
|
36 |
|
37 |
|
38 | console.error('='.repeat(80));
|
39 | console.error('Performing restore on ' + databaseUrl.replace(/\/\/.+@/g, '//****:****@') + ' using configuration:');
|
40 | console.error(JSON.stringify(opts, null, 2).replace(/"iamApiKey": "[^"]+"/, '"iamApiKey": "****"'));
|
41 | console.error('='.repeat(80));
|
42 |
|
43 | restoreBatchDebug.enabled = !program.quiet;
|
44 |
|
45 | return couchbackup.restore(
|
46 | process.stdin,
|
47 | databaseUrl,
|
48 | opts,
|
49 | error.terminationCallback
|
50 | ).on('restored', function(obj) {
|
51 | restoreBatchDebug('restored', obj.total);
|
52 | }).on('error', function(e) {
|
53 | restoreDebug('ERROR', e);
|
54 | }).on('finished', function(obj) {
|
55 | restoreDebug('finished', obj);
|
56 | });
|