Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def backup_lmdb(envpath, dstdir):
datafile = os.path.join(envpath, 'data.mdb')
stat = os.stat(datafile)
map_size = stat.st_size
parser = lmdb.tool.make_parser()
opts, args = parser.parse_args(['copy', '--compact', '-e', envpath, dstdir])
env = lmdb.open(
opts.env,
map_size=map_size,
subdir=True,
max_dbs=opts.max_dbs,
create=False,
readonly='READ'
)
lmdb.tool.ENV = env
tick = time.time()
# use the builtin lmdb command
ret = lmdb.tool.cmd_copy(opts, args[1:])
stat = os.stat(datafile)
map_size = stat.st_size
parser = lmdb.tool.make_parser()
opts, args = parser.parse_args(['copy', '--compact', '-e', envpath, dstdir])
env = lmdb.open(
opts.env,
map_size=map_size,
subdir=True,
max_dbs=opts.max_dbs,
create=False,
readonly='READ'
)
lmdb.tool.ENV = env
tick = time.time()
# use the builtin lmdb command
ret = lmdb.tool.cmd_copy(opts, args[1:])
logger.warning(f'lmdb ret: {ret}')
tock = time.time()
logger.info(f'backup took: {tock-tick:.2f} seconds')
env.close()