Search code examples
key-valuekey-value-storeleveldb

Can LevelDB snapshots survive a close of the database?


I'm wondering if the 'snapshot' facility of the LevelDB library can create a snapshot reference that could be saved even after a close of the open database object (and thus reused on a subsequent open).

I suspect not, which leads to a followup: is there a good/recommended way to make a consistent backup of the database as of a snapshot-instant, ideally even while other activity continues? (That is, short of iterating the entire snapshot keyrange via the API?)

(Essentially I'm looking for something analogous to saving aside the append-only JDB log files of BerkeleyDB-JE up through a certain checkpointed place.)


Solution

  • A good approach would be to close the DB, then hard link all the sst files (cp -l) and copy all the non-sst files. This way you only actually copy a small amount of data (size of your log, 4MB by default). Then you can open the DB again.

    You do have to block while this happens, but hopefully it should be quick.