Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepy
titleverify_leveldb.py
collapsetrue
#!/usr/bin/python
import sys
import leveldb
from datetime import datetime
import subprocess
if (len(sys.argv) != 2) :
  print 'Usage:'
  print 'python verify_leveldb.py /path/to/leveldb/cache/'
  sys.exit(1)
dbpath = sys.argv[1]
try:
  startTime = datetime.now()
  print sys.argv[0], ": Inspecting db: ", dbpath
  db = leveldb.LevelDB(dbpath,  create_if_missing=False, paranoid_checks=True)
  it = db.RangeIter(None, None, True, True, True)
  records = 0;
  for key, value in it:
    records = records + 1
  print sys.argv[0], ": Backup verfiication successful!"
  print sys.argv[0], ": Total records: ", records
  print sys.argv[0], ": Time taken:", datetime.now() - startTime
except:
  print sys.argv[0], ": Backup verfication failed!"
  print sys.argv[0], ": Unexpected error:", sys.exc_info()[0]
  raise
  exit(1)
# Rename ldb files to sst (Python API uses ldb extension, whereas infinispan expects sst)
script = 'for f in ' + dbpath + '/*.ldb; do mv $f "${f%.ldb}.sst"; done'
subprocess.call(['/bin/bash', '-c', script])

Repairing Corrupt LevelDB 

Anchor
Repairing Corrupt LevelDB
Repairing Corrupt LevelDB

 

 

When the LevelDB database becomes corrupted, the RepairDB option provided by the LevelDB API can be used to recover as much as data as possible. In LevelDB, the manifest file holds account of all files and their corresponding key ranges. The recovery process inspects each file in the leveldb directory and updates the manifest accordingly. This implies that even with a successful repair missing-files could lead to loss of data, which in turn can prevent a successful restoration of the repository. 

...