Skip to content

Commit

Permalink
only check for rsync exe
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Feb 14, 2024
1 parent 23c784a commit 7db646f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
24 changes: 7 additions & 17 deletions disk_objectstore/backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ def __init__(
dest: str,
logger: logging.Logger,
keep: int = 1,
exes: Optional[dict] = None,
rsync_exe: Optional[str] = None,
) -> None:
self.dest = dest
self.keep = keep
self.logger = logger
self.remote, self.path = split_remote_and_path(dest)

if exes is None:
self.exes = {}
else:
self.exes = exes

# make sure rsync gets added so it gets validated
if "rsync" not in self.exes:
self.exes["rsync"] = "rsync"
self.rsync_exe = rsync_exe if rsync_exe is not None else "rsync"

# Validate the backup config inputs

Expand All @@ -77,10 +69,10 @@ def __init__(
if self.remote:
self.check_if_remote_accessible()

if self.exes:
for _, path in self.exes.items():
if not is_exe_found(path):
raise ValueError(f"Input validation failed: {path} not accessible.")
if not is_exe_found(self.rsync_exe):
raise ValueError(
f"Input validation failed: {self.rsync_exe} not accessible."
)

if not self.check_path_exists(self.path):
success = self.run_cmd(["mkdir", str(self.path)])[0]
Expand Down Expand Up @@ -148,9 +140,7 @@ def call_rsync( # pylint: disable=too-many-arguments
"""

assert "rsync" in self.exes

all_args = [self.exes["rsync"], "-azh", "-vv", "--no-whole-file"]
all_args = [self.rsync_exe, "-azh", "-vv", "--no-whole-file"]
if extra_args:
all_args += extra_args
if link_dest:
Expand Down
5 changes: 3 additions & 2 deletions disk_objectstore/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A small CLI tool for managing stores."""

import dataclasses
import json
import logging
Expand Down Expand Up @@ -228,7 +229,7 @@ def backup(
by OpenSSH, such as adding configuration options to ~/.ssh/config (e.g. to allow for passwordless
login - recommended, since this script might ask multiple times for the password).
NOTE: 'rsync' and other UNIX-specific commands are called, thus the command will not work on
NOTE: 'rsync' and other UNIX-specific commands are called, thus the command will likely not work on
non-UNIX environments.
"""

Expand All @@ -244,8 +245,8 @@ def backup(
backup_manager = backup_utils.BackupManager(
dest,
backup_utils.backup_logger,
exes={"rsync": rsync_exe},
keep=keep,
rsync_exe=rsync_exe,
)
backup_manager.backup_auto_folders(
lambda path, prev: backup_utils.backup_container(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_inaccessible_exe():
dest = "/tmp/test"
rsync_exe = f"_{_random_string()}"
with pytest.raises(ValueError, match=f"{rsync_exe} not accessible."):
BackupManager(dest, backup_utils.backup_logger, exes={"rsync": rsync_exe})
BackupManager(dest, backup_utils.backup_logger, rsync_exe=rsync_exe)


def test_inaccessible_path():
Expand Down

0 comments on commit 7db646f

Please sign in to comment.