Skip to content

Commit

Permalink
use rsync legacy progress for v<3 (default on macos)
Browse files Browse the repository at this point in the history
  • Loading branch information
eimrek committed Feb 22, 2024
1 parent aaf77eb commit 2790ae9
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions disk_objectstore/backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import logging
import random
import re
import shutil
import sqlite3
import string
Expand Down Expand Up @@ -115,7 +116,23 @@ def run_cmd(

return success, res.stdout

def call_rsync( # pylint: disable=too-many-arguments
def get_rsync_major_version(self):
"""
Get the rsync major version.
"""
result = subprocess.run(
[self.rsync_exe, "--version"],
capture_output=True,
text=True,
check=False,
)
pattern = r"rsync\s+version\s+(\d+\.\d+\.\d+)"
match = re.search(pattern, result.stdout)
if match:
return int(match.group(1).split(".")[0])
return None

Check warning on line 133 in disk_objectstore/backup_utils.py

View check run for this annotation

Codecov / codecov/patch

disk_objectstore/backup_utils.py#L133

Added line #L133 was not covered by tests

def call_rsync( # pylint: disable=too-many-arguments,too-many-branches
self,
src: Path,
dest: Path,
Expand All @@ -142,8 +159,20 @@ def call_rsync( # pylint: disable=too-many-arguments
self.rsync_exe,
"-azh",
"--no-whole-file",
"--info=progress2,stats1",
]

capture_output = True
if LOGGER.isEnabledFor(logging.INFO):
capture_output = False
rsync_version = self.get_rsync_major_version()
if rsync_version and rsync_version >= 3:
# These options show progress in a nicer way but
# they're only available for rsync version 3+
all_args += ["--info=progress2,stats1"]
else:
LOGGER.info("rsync version <3 detected: showing 'legacy' progress.")
all_args += ["--progress"]

if LOGGER.isEnabledFor(logging.DEBUG):
all_args += ["-vv"]
if extra_args:
Expand Down Expand Up @@ -171,10 +200,6 @@ def call_rsync( # pylint: disable=too-many-arguments
cmd_str = " ".join(all_args)
LOGGER.info("Running '%s'", cmd_str)

capture_output = True
if LOGGER.isEnabledFor(logging.INFO):
capture_output = False

res = subprocess.run(
all_args, capture_output=capture_output, text=True, check=False
)
Expand Down

0 comments on commit 2790ae9

Please sign in to comment.