dbtool: update backup location

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-01-27 07:57:51 -05:00
parent 2392ccd719
commit 46a92e1900
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 7 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import pathlib
import base64 import base64
import tempfile import tempfile
import re import re
import time
from typing import Any, Dict, Optional, TextIO, Tuple from typing import Any, Dict, Optional, TextIO, Tuple
import lmdb import lmdb
@ -157,10 +158,13 @@ def restore(args: Dict[str, Any]):
print(f"Restoring backup from '{input_db}' to '{dest_path}'...") print(f"Restoring backup from '{input_db}' to '{dest_path}'...")
bkp_dir: Optional[pathlib.Path] = None bkp_dir: Optional[pathlib.Path] = None
if dest_path.joinpath("data.mdb").exists(): if dest_path.joinpath("data.mdb").exists():
tmp_dir = pathlib.Path(tempfile.gettempdir()) bkp_dir = dest_path.parent.joinpath("backup")
bkp_dir = tmp_dir.joinpath("moonrakerdb_backup") if not bkp_dir.exists():
bkp_dir = pathlib.Path(tempfile.gettempdir())
str_time = time.strftime("%Y%m%dT%H%M%SZ", time.gmtime())
bkp_dir = bkp_dir.joinpath(f"{str_time}/database")
if not bkp_dir.is_dir(): if not bkp_dir.is_dir():
bkp_dir.mkdir() bkp_dir.mkdir(parents=True)
print(f"Warning: database file at found in '{dest_path}', " print(f"Warning: database file at found in '{dest_path}', "
"all data will be overwritten. Copying existing DB " "all data will be overwritten. Copying existing DB "
f"to '{bkp_dir}'") f"to '{bkp_dir}'")