db: improve backups.
This commit is contained in:
parent
91324b2531
commit
b346397449
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user