UNPKG

2 kBJavaScriptView Raw
1#!/usr/bin/env node
2// Copyright © 2017, 2021 IBM Corp. All rights reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15'use strict';
16
17const error = require('../includes/error.js');
18const cliutils = require('../includes/cliutils.js');
19const couchbackup = require('../app.js');
20const parser = require('../includes/parser.js');
21const debug = require('debug');
22const restoreDebug = debug('couchbackup:restore');
23const restoreBatchDebug = debug('couchbackup:restore:batch');
24
25restoreDebug.enabled = true;
26
27const program = parser.parseRestoreArgs();
28const databaseUrl = cliutils.databaseUrl(program.url, program.db);
29const opts = {
30 bufferSize: program.bufferSize,
31 parallelism: program.parallelism,
32 requestTimeout: program.requestTimeout,
33 iamApiKey: program.iamApiKey,
34 iamTokenUrl: program.iamTokenUrl
35};
36
37// log configuration to console
38console.error('='.repeat(80));
39console.error('Performing restore on ' + databaseUrl.replace(/\/\/.+@/g, '//****:****@') + ' using configuration:');
40console.error(JSON.stringify(opts, null, 2).replace(/"iamApiKey": "[^"]+"/, '"iamApiKey": "****"'));
41console.error('='.repeat(80));
42
43restoreBatchDebug.enabled = !program.quiet;
44
45return couchbackup.restore(
46 process.stdin, // restore from 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});