Commit 19681c8e by serpucga

Enhancements to path of recovery files

Now a directory "recovery" is created to contain these kind of files. Besides, they are no longer hidden files and they will always be unique, because they contain a timestamp in their filename (this way a recovery file won't unexpectedly a previous recovery file for the same collection)
parent 174863a2
pymongodump
recovery
tests.py
.mypy_cache
.recovery*
......@@ -3,6 +3,7 @@ import pymongo
import json
import re
import time
import datetime
import multiprocessing as mp
from math import ceil
from typing import List
......@@ -43,7 +44,7 @@ def filesystem_writer(
if recovery_file:
recovery_file_path = recovery_file
else:
recovery_file_path = ".recovery_" + database + ".csv"
recovery_file_path = build_recovery_filepath(database)
create_recovery_file(
recovery_file_path, host, port, database, pagesize)
......@@ -274,6 +275,25 @@ def dump_recovery_file(
"Generated recovery file at {}".format(recovery_file_path))
def build_recovery_filepath(dbname: str) -> str:
"""
Build the path of a recovery file
:param dbname: name of the database being queried
:returns: the path of the recovery file generated in this execution
"""
recovery_dir = "./recovery"
if not os.path.isdir(recovery_dir):
os.mkdir(recovery_dir)
now = datetime.datetime.now()
datetime_str = "%04d%02d%02d-%02d%02d%02d" %\
(now.year, now.month, now.day, now.hour, now.minute, now.second)
recovery_file_path = os.path.join(
recovery_dir, "recovery_" + dbname + "_" + datetime_str + ".csv")
return recovery_file_path
def create_recovery_file(
file_path: str,
host: str,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment