Skip to content

Commit c29e7b2

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: add archive_tdb function
Add an archive_tdb function that archives (moves) the tdb files that converted into ctdb backing files. Signed-off-by: John Mulligan <[email protected]>
1 parent 85c10e5 commit c29e7b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sambacc/ctdb.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,23 @@ def _convert_tdb_file(tdb_path: str, dest_dir: str, pnn: int = 0) -> None:
586586
subprocess.check_call(list(cmd))
587587

588588

589+
def archive_tdb(iconfig: config.InstanceConfig, dest_dir: str) -> None:
590+
"""Arhive TDB files into a given directory."""
591+
# TODO: these paths should be based on our instance config, not hard coded
592+
try:
593+
os.mkdir(dest_dir)
594+
_logger.debug("dest_dir: %r created", dest_dir)
595+
except FileExistsError:
596+
_logger.debug("dest_dir: %r already exists", dest_dir)
597+
for tdbfile in _SRC_TDB_FILES:
598+
for parent in _SRC_TDB_DIRS:
599+
tdb_path = os.path.join(parent, tdbfile)
600+
if _has_tdb_file(tdb_path):
601+
dest_path = os.path.join(dest_dir, tdbfile)
602+
_logger.info("archiving: %r -> %r", tdb_path, dest_path)
603+
os.rename(tdb_path, dest_path)
604+
605+
589606
def check_nodestatus(cmd: samba_cmds.SambaCommand = samba_cmds.ctdb) -> None:
590607
cmd_ctdb_check = cmd["nodestatus"]
591608
samba_cmds.execute(cmd_ctdb_check)

0 commit comments

Comments
 (0)