Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

422 merge db tool #423

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions scripts/merge_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import plyvel
import sys

def merge_databases(source_db_paths, target_db_path):
try:
target_db = plyvel.DB(target_db_path, create_if_missing=True)

with target_db.write_batch() as batch:
for source_db_path in source_db_paths:
source_db = plyvel.DB(source_db_path, create_if_missing=False)
for key, value in source_db:
batch.put(key, value)
source_db.close()

print("Merge successful!")

except Exception as e:
print("Error:", e)

finally:
if target_db:
target_db.close()

if __name__ == "__main__":
if len(sys.argv) < 4:
print("Usage: python merge_leveldb.py source_db_path1 source_db_path2 ... target_db_path")
sys.exit(1)

source_db_paths = sys.argv[1:-1]
target_db_path = sys.argv[-1]

merge_databases(source_db_paths, target_db_path)
Loading