Skip to content

Conversation

@infinisil
Copy link

Previously when running borg in a systemd service (and similar when piping to a file and co.), these problems occurred:

  • The carriage return both made it so that journald interpreted the output as binary, therefore not printing the text, while also not buffering correctly, so that log output was only available every once in a while in the form [40k blob data]. This can partially be worked around by using journalctl -a to view the logs, which at least prints the text, though only sporadically
  • The path was getting truncated to a short length, since the default get_terminal_size returns a column width of 80, which isn't relevant when printing to e.g. journald

This commit fixes this by introducing a new code path for when stderr is a tty, which always prints the full paths and never ends with a carriage return.

Unfortunately I don't have the time right now to make the tests work nor add new ones to cover this, but I figured at least getting this patch out of my local repository is better than keeping it for myself, it definitely works in my deployment. Because of this I'll mark this PR a draft for now, feel free to close it if neither me nor anybody else manages to make the tests satisfactory in a reasonable time.

Previously when running borg in a systemd service (and similar when piping to a file and co.),
these problems occurred:
- The carriage return both made it so that journald interpreted the output as
  binary, therefore not printing the text, while also not buffering
  correctly, so that log output was only available every once in a while
  in the form [40k blob data]. This can partially be worked around by
  using `journalctl -a` to view the logs, which at least prints the
  text, though only sporadically
- The path was getting truncated to a short length, since the default
  get_terminal_size returns a column width of 80, which isn't relevant
  when printing to e.g. journald

This commit fixes this by introducing a new code path for when stderr is
a tty, which always prints the full paths and never ends with a carriage
return.
return format_file_size(self.usize, iec=self.iec)

def show_progress(self, item=None, final=False, stream=None, dt=None):
def show_progress(self, item=None, final=False, stream=sys.stderr, dt=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would determine the default (the value of sys.stderr) at import time, while the original code determines it later, when the code is actually called. IIRC, that could be important.

So, to not risk any breakage, just keep the stream=None default and add a first line inside the method:

stream = stream or sys.stderr

And then use stream everywhere in the function where appropriate.

end = "\n"
elif not stream.isatty():
if not final:
msg = "{0.osize_fmt} O {0.csize_fmt} C {0.usize_fmt} D {0.nfiles} N ".format(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, the other branch uses U for usize.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also:

E                   AttributeError: 'Statistics' object has no attribute 'csize_fmt'

@ThomasWaldmann
Copy link
Member

Besides some technicalities in previous feedback, there is also something rather fundamental:

--progress is intended for interactive console use and not for logging (where one either would rather have little output or full --list output or list output filtered for the interesting stuff, e.g. by using --filter=AME).

ThomasWaldmann added a commit to ThomasWaldmann/borg that referenced this pull request Oct 11, 2025
Previously when running borg in a systemd service (and similar when piping to
a file and co.), these problems occurred:

- The carriage return both made it so that journald interpreted the output as
  binary, therefore not printing the text, while also not buffering
  correctly, so that log output was only available every once in a while
  in the form [40k blob data]. This can partially be worked around by
  using `journalctl -a` to view the logs, which at least prints the text,
  though only sporadically.

- The path was getting truncated to a short length, since the default
  get_terminal_size returns a column width of 80, which isn't relevant
  when printing to e.g. journald.

This commit fixes this by introducing a new code path for when stream is
not a tty, which always prints the full paths and ends lines with a linefeed.

This is based on unfinished PR borgbackup#8939 by @infinisil, thanks for your suggestion!
@ThomasWaldmann
Copy link
Member

Thanks for your suggestion, I am finishing this in #9055.

ThomasWaldmann added a commit to ThomasWaldmann/borg that referenced this pull request Oct 11, 2025
Previously when running borg in a systemd service (and similar when piping to
a file and co.), these problems occurred:

- The carriage return both made it so that journald interpreted the output as
  binary, therefore not printing the text, while also not buffering
  correctly, so that log output was only available every once in a while
  in the form [40k blob data]. This can partially be worked around by
  using `journalctl -a` to view the logs, which at least prints the text,
  though only sporadically.

- The path was getting truncated to a short length, since the default
  get_terminal_size returns a column width of 80, which isn't relevant
  when printing to e.g. journald.

This commit fixes this by introducing a new code path for when stream is
not a tty, which always prints the full paths and ends lines with a linefeed.

This is based on unfinished PR borgbackup#8939 by @infinisil, thanks for your suggestion!
@infinisil infinisil deleted the non-tty-progress branch October 11, 2025 14:32
ThomasWaldmann added a commit to ThomasWaldmann/borg that referenced this pull request Oct 15, 2025
Previously when running borg in a systemd service (and similar when piping to
a file and co.), these problems occurred:

- The carriage return both made it so that journald interpreted the output as
  binary, therefore not printing the text, while also not buffering
  correctly, so that log output was only available every once in a while
  in the form [40k blob data]. This can partially be worked around by
  using `journalctl -a` to view the logs, which at least prints the text,
  though only sporadically.

- The path was getting truncated to a short length, since the default
  get_terminal_size returns a column width of 80, which isn't relevant
  when printing to e.g. journald.

This commit fixes this by introducing a new code path for when stream is
not a tty, which always prints the full paths and ends lines with a linefeed.

This is based on unfinished PR borgbackup#8939 by @infinisil, thanks for your suggestion!

Forward port of PR borgbackup#9055 to master.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants