Skip to content

borg info tracebacks on empty directory #4764

@witten

Description

@witten

Have you checked borgbackup docs, FAQ, and open Github issues?

Yes, all three. Specifically, read through usage init/info docs, FAQ, and searched open and closed issues.

Is this a BUG / ISSUE report or a QUESTION?

BUG

System information. For client/server mode post info for both machines.

Your borg version (borg -V).

1.1.10

Operating system (distribution) and version.

Manjaro Linux 18.1-rc10 with Linux kernel 4.19.69

Hardware / network configuration, and filesystems used.

Lenovo ThinkPad X1 Carbon. No network used with Borg. ext4 filesystem.

How much data is handled by borg?

None.

Full borg commandline that lead to the problem (leave away excludes and passwords)

mkdir empty-dir ; borg info empty-dir

Describe the problem you're observing.

Borg experiences a traceback and exits unceremoniously with an error exit code when borg info is run on an empty directory. Instead, I would expect Borg not to traceback and exit gracefully (with an error exit code). Side note: This directory is empty because it is a Docker volume mount, which when mounted for the first time (if it doesn't exist on the host previously), manifests as an empty directory.

My use case, for context: Within a Borg wrapper script, I'm trying to use borg info to probe for whether a Borg repository already exists, so I know whether I need to run borg init or not. I can't just run borg init unconditionally, because I can't tell from its exit code whether the repository already exists. (And I can't capture stderr and try to parse the "A repository already exists" message, because I need stderr to pass through to the user in case there are interactive repository creation messages on stderr.)

So, I'm hoping that I can use borg info or a similar Borg sub-command to determine whether a repository exists.. Even if it's on an empty directory. The existing traceback is confusing to my users, so it would be great to have a traceback-free way to determine whether a repository exists in a directory.

I originally thought of just probing for the existence of the <repository-directory-name>/config path without using Borg, but that doesn't handle the remote repository case.

Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.

Yes. Just run borg info empty-dir again on the empty directory.

Include any warning/errors/backtraces from the system logs

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/borg/repository.py", line 179, in __del__
    assert False, "cleanup happened in Repository.__del__"
AssertionError: cleanup happened in Repository.__del__
Local Exception
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/borg/archiver.py", line 4501, in main
    exit_code = archiver.run(args)
  File "/usr/lib/python3.7/site-packages/borg/archiver.py", line 4433, in run
    return set_ec(func(args))
  File "/usr/lib/python3.7/site-packages/borg/archiver.py", line 151, in wrapper
    with repository:
  File "/usr/lib/python3.7/site-packages/borg/repository.py", line 189, in __enter__
    self.open(self.path, bool(self.exclusive), lock_wait=self.lock_wait, lock=self.do_lock)
  File "/usr/lib/python3.7/site-packages/borg/repository.py", line 396, in open
    with open(os.path.join(self.path, 'config')) as fd:
FileNotFoundError: [Errno 2] No such file or directory: '/root/tmp/empty-dir/config'

Platform: Linux flux 4.19.69-1-MANJARO #1 SMP PREEMPT Thu Aug 29 08:51:46 UTC 2019 x86_64
Linux: arch Manjaro Linux
Borg: 1.1.10  Python: CPython 3.7.4 msgpack: 0.5.6
PID: 988  CWD: /root/tmp
sys.argv: ['/usr/bin/borg', 'info', 'empty-dir']
SSH_ORIGINAL_COMMAND: None

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions