diff --git a/lib/db/lowlevelup.js b/lib/db/lowlevelup.js index 5e94fc9c..ec0e8501 100644 --- a/lib/db/lowlevelup.js +++ b/lib/db/lowlevelup.js @@ -408,17 +408,20 @@ LowlevelUp.prototype.checkVersion = function checkVersion(key, version, callback LowlevelUp.prototype.clone = function clone(path, callback) { var self = this; - var options = { keys: true, values: true }; + var iter = { keys: true, values: true }; + var options = utils.merge({}, this.options); + var hwm = 256 << 20; + var total = 0; var tmp, batch; assert(!this.loading); assert(!this.closing); assert(this.loaded); - this.options.createIfMissing = true; - this.options.errorIfExists = true; + options.createIfMissing = true; + options.errorIfExists = true; - tmp = new LowlevelUp(path, this.options); + tmp = new LowlevelUp(path, options); function done(err) { tmp.close(function(e) { @@ -434,10 +437,13 @@ LowlevelUp.prototype.clone = function clone(path, callback) { batch = tmp.batch(); - self.each(options, function(key, value, next, i) { + self.each(iter, function(key, value, next) { batch.put(key, value); - if (i % 1000 === 0) { + total += value.length; + + if (total >= hwm) { + total = 0; batch.write(function(err) { if (err) return next(err); diff --git a/lib/http/rpc.js b/lib/http/rpc.js index f68cb152..418af626 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -2581,7 +2581,11 @@ RPC.prototype.backupwallet = function backupwallet(args, callback) { dest = toString(args[0]); - this.walletdb.db.backup(dest, callback); + this.walletdb.backup(dest, function(err) { + if (err) + return callback(err); + callback(null, null); + }); }; RPC.prototype.dumpprivkey = function dumpprivkey(args, callback) { diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index b434781c..41bb89c2 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -278,6 +278,16 @@ WalletDB.prototype._close = function close(callback) { }); }; +/** + * Backup the wallet db. + * @param {String} path + * @param {Function} callback + */ + +WalletDB.prototype.backup = function backup(path, callback) { + this.db.backup(path, callback); +}; + /** * Get current wallet wid depth. * @private