includes/backup.js
function processBatchSet(db, parallelism, log, batches, ee, start, grandtotal, callback) {
  var hasErrored = false;
  var total = grandtotal;

  // queue to process the fetch requests in an orderly fashion using _bulk_get
  var q = async.queue(function(payload, done) {
    var output = [];
    var thisBatch = payload.batch;
    delete payload.batch;
    delete payload.command;

    function logCompletedBatch(batch) {
      if (log) {
        fs.appendFile(log, ':d batch' + thisBatch + '\n', done);
      } else {
        done();
      }
    }

    // do the /db/_bulk_get request
    // Note: this should use built-in _bulk_get, but revs is not accepted as
    // part of the request body by the server yet. Working around using request
    // method to POST with a query string.
    db.server.request(
      { method: 'POST', db: db.config.db, path: '_bulk_get', qs: { revs: true }, body: payload },
      function(err, body) {
        if (err) {
          if (!hasErrored) {
            hasErrored = true;
            err = error.convertResponseError(err);
            // Kill the queue for fatal errors
            q.kill();
            ee.emit('error', err);
          }
          done();
        } else {
          // create an output array with the docs returned
          body.results.forEach(function(d) {
            if (d.docs) {
              d.docs.forEach(function(doc) {
                if (doc.ok) {
                  output.push(doc.ok);
                }
              });
            }
          });
          total += output.length;
          var t = (new Date().getTime() - start) / 1000;
          ee.emit('received', {
            batch: thisBatch,
            data: output,
            length: output.length,
            time: t,
            total: total
          }, q, logCompletedBatch);
        }
      });
  }, parallelism);

  for (var i in batches) {
    q.push(batches[i]);
  }

  q.drain = function() {
    callback(null, { total: total });
  };
}
function processBatchSet(db, parallelism, log, batches, ee, start, grandtotal, callback) {
  var hasErrored = false;
  var total = grandtotal;

  // queue to process the fetch requests in an orderly fashion using _bulk_get
  var q = async.queue(function(payload, done) {
    var output = [];
    var thisBatch = payload.batch;
    delete payload.batch;
    delete payload.command;

    function logCompletedBatch(batch) {
      if (log) {
        fs.appendFile(log, ':d batch' + thisBatch + '\n', done);
      } else {
        done();
      }
    }

    // do the /db/_bulk_get request
    // Note: this should use built-in _bulk_get, but revs is not accepted as
    // part of the request body by the server yet. Working around using request
    // method to POST with a query string.
    db.server.request(
      { method: 'POST', db: db.config.db, path: '_bulk_get', qs: { revs: true }, body: payload },
      function(err, body) {
        if (err) {
          if (!hasErrored) {
            hasErrored = true;
            err = error.convertResponseError(err);
            // Kill the queue for fatal errors
            q.kill();
            ee.emit('error', err);
          }
          done();
        } else {
          // create an output array with the docs returned
          body.results.forEach(function(d) {
            if (d.docs) {
              d.docs.forEach(function(doc) {
                if (doc.ok) {
                  output.push(doc.ok);
                }
              });
            }
          });
          total += output.length;
          var t = (new Date().getTime() - start) / 1000;
          ee.emit('received', {
            batch: thisBatch,
            data: output,
            length: output.length,
            time: t,
            total: total
          }, q, logCompletedBatch);
        }
      });
  }, parallelism);

  for (var i in batches) {
    q.push(batches[i]);
  }

  q.drain = function() {
    callback(null, { total: total });
  };
}
function processBatchSet ( db , parallelism , log , batches , ee , start , grandtotal , callback ) { var hasErrored = false ; var total = grandtotal ; // queue to process the fetch requests in an orderly fashion using _bulk_get var q = async . queue ( function ( payload , done ) { var output = [ ] ; var thisBatch = payload . batch ; delete payload . batch ; delete payload . command ; function logCompletedBatch ( batch ) { if ( log ) { fs . appendFile ( log , ':d batch' + thisBatch + '\n' , done ) ; } else { done ( ) ; } } // do the /db/_bulk_get request // Note: this should use built-in _bulk_get, but revs is not accepted as // part of the request body by the server yet. Working around using request // method to POST with a query string. db . server . request ( { method : 'POST' , db : db . config . db , path : '_bulk_get' , qs : { revs : true } , body : payload } , function ( err , body ) { if ( err ) { if ( ! hasErrored ) { hasErrored = true ; err = error . convertResponseError ( err ) ; // Kill the queue for fatal errors q . kill ( ) ; ee . emit ( 'error' , err ) ; } done ( ) ; } else { // create an output array with the docs returned body . results . forEach ( function ( d ) { if ( d . docs ) { d . docs . forEach ( function ( doc ) { if ( doc . ok ) { output . push ( doc . ok ) ; } } ) ; } } ) ; total += output . length ; var t = ( new Date ( ) . getTime ( ) - start ) / 1000 ; ee . emit ( 'received' , { batch : thisBatch , data : output , length : output . length , time : t , total : total } , q , logCompletedBatch ) ; } } ) ; } , parallelism ) ; for ( var i in batches ) { q . push ( batches [ i ] ) ; } q . drain = function ( ) { callback ( null , { total : total } ) ; } ; }
Download a set of batches retrieved from a log file. When a download is
complete, add a line to the logfile indicating such.

@param {any} db - nodejs-cloudant database
@param {any} parallelism - number of concurrent requests to make
@param {any} log - log file to drive downloads from
@param {any} batches - batches to download
@param {any} ee - event emitter for progress. This funciton emits
received and error events.
@param {any} start - time backup started, to report deltas
@param {any} grandtotal - count of documents downloaded prior to this set
of batches
@param {any} callback - completion callback, (err, {total: number}).
Download a set of batches retrieved from a log file . When a download is complete add a line to the logfile indicating such .