diff --git a/disk_objectstore/backup_utils.py b/disk_objectstore/backup_utils.py index ef51898..e5aa0a2 100644 --- a/disk_objectstore/backup_utils.py +++ b/disk_objectstore/backup_utils.py @@ -67,24 +67,10 @@ def __init__( if "rsync" not in self.exes: self.exes["rsync"] = "rsync" - self.validate() + # Validate the backup config inputs - def check_if_remote_accessible(self): - """Check if remote host is accessible via ssh""" - self.logger.info(f"Checking if '{self.remote}' is accessible...") - success = self.run_cmd(["exit"])[0] - if not success: - raise BackupError(f"Remote '{self.remote}' is not accessible!") - self.logger.info("Success! '%s' is accessible!", self.remote) - - def check_path_exists(self, path: Path) -> bool: - cmd = ["[", "-e", str(path), "]"] - return self.run_cmd(cmd)[0] - - def validate(self): - """Validate the backup config inputs""" if self.keep < 0: - raise BackupError( + raise ValueError( "Input validation failed: keep variable can't be negative!" ) @@ -94,17 +80,27 @@ def validate(self): if self.exes: for _, path in self.exes.items(): if not is_exe_found(path): - raise BackupError( - f"Input validation failed: {path} not accessible." - ) + raise ValueError(f"Input validation failed: {path} not accessible.") if not self.check_path_exists(self.path): success = self.run_cmd(["mkdir", str(self.path)])[0] if not success: - raise BackupError( + raise ValueError( f"Input validation failed: Couldn't access/create '{str(self.path)}'!" ) + def check_if_remote_accessible(self): + """Check if remote host is accessible via ssh""" + self.logger.info(f"Checking if '{self.remote}' is accessible...") + success = self.run_cmd(["exit"])[0] + if not success: + raise BackupError(f"Remote '{self.remote}' is not accessible!") + self.logger.info("Success! '%s' is accessible!", self.remote) + + def check_path_exists(self, path: Path) -> bool: + cmd = ["[", "-e", str(path), "]"] + return self.run_cmd(cmd)[0] + def run_cmd( self, args: list,