Commit Graph

2748 Commits

Author SHA1 Message Date
Thomas Waldmann e7bd18d7f3
create: add the slashdot hack, fixes #4685 2024-02-20 04:08:09 +01:00
Thomas Waldmann 43a20b052e
add ConnectionBrokenWithHint for BrokenPipeErrors and similar, see #7016
no traceback, but error message and specific exit code.
2024-02-20 00:17:55 +01:00
Thomas Waldmann 45815554ce
check_can_create_repository: deal with PermissionErrors, see #7016
borg init calls this. If there is a PermissionError, it is
usually fs permission issue at path or its parent directory.

Don't give a traceback, but rather an error msg and a specific exit code.
2024-02-20 00:07:43 +01:00
Thomas Waldmann 83c069ce5a
better error msg for corrupted key data, fixes #8016 2024-02-19 19:23:48 +01:00
Thomas Waldmann 334fbab897
refactor: use less binascii
our own hex_to_bin / bin_to_hex is more comfortable to use.

also: optimize remaining binascii usage / imports.
2024-02-19 02:16:19 +01:00
Thomas Waldmann ab0b111af0
give clean error msg for invalid nonce file, see #7967
this is a fwd port from 1.4-maint. as we don't have nonce files
any more in master, only the generally useful stuff has been ported.

- add Error / ErrorWithTraceback exception classes to RPC layer.
- add hex_to_bin helper
2024-02-18 14:47:52 +01:00
Thomas Waldmann 930ecd845a
fix CommandError args, fixes 8029
this is a fwd port from 1.4-maint and most of it was
already done in master, so only a minor change in here.
2024-02-18 14:18:33 +01:00
kmille 1f5cc355a3
borg with-lock: catch exception, print error msg, fixes #8022 2024-02-18 13:36:10 +01:00
Thomas Waldmann ed28eb9e03
fix: Error/CommandError have a output format for 1 argument 2024-02-18 04:40:32 +01:00
Thomas Waldmann d7e2e2cea9
fix mypy error 2024-02-17 23:01:46 +01:00
Thomas Waldmann a0a07ab464
use get_reset_ec to internally re-init ec/warnings
if we do multiple calls to Archiver.do_something(),
we need to reset the ec / warnings after each call,
otherwise they will keep growing (in severity, in length).
2024-02-17 22:37:44 +01:00
Thomas Waldmann b53c86cf4c
refactor (re-)init of exit_code and warnings_list globals
stop directly accessing the variables from other modules.

prefix with underscore to indicate that these shall
only be used within this module and every other user
shall call the respective functions.
2024-02-17 22:29:18 +01:00
Thomas Waldmann abe6545853
do not return the rc from Archiver methods
this is not needed and getting rid of it makes
the code / behaviour simpler to understand:

if a fatal error is detected, we throw an exception.

if we encounter something warning worthy, we emit and collect the warning.

in a few cases, we directly call set_ec to set the
exit code as needed, e.g. if passing it through
from a subprocess.

also:
- get rid of Archiver.exit_code
- assert that return value of archiver methods is None
- fix a print_warning call to use the correct formatting method
2024-02-17 22:07:47 +01:00
Thomas Waldmann 2e05c234b6
BackupErrors get caught and give warning RCs
also: use more union operators rather than .union()
2024-02-15 18:15:10 +01:00
Thomas Waldmann 97dd287584
raise BackupOSError subclasses 2024-02-15 17:53:53 +01:00
Thomas Waldmann 9ac4672254
add NotFoundWarning 2024-02-15 17:04:21 +01:00
Thomas Waldmann 4adc782100
print_warning*: support warning msgids, fixes #7080 2024-02-14 02:22:35 +01:00
Thomas Waldmann 5168a97782
extend errorlist script to warnings, update docs 2024-02-14 02:04:44 +01:00
Thomas Waldmann 982aeb56a7
more detailled warnings for source file OSErrors 2024-02-14 02:00:19 +01:00
Thomas Waldmann e8fa4986cc
BackupError->BackupWarning, BackupOSError->BackupOSWarning 2024-02-14 01:59:08 +01:00
Thomas Waldmann 900a1674df
move Backup*Error to errors module 2024-02-14 01:40:55 +01:00
Thomas Waldmann c704e5ea9e
new warnings infrastructure to support modern exit codes
- implement updating exit code based on severity, including modern codes
- extend print_warning with kwargs wc (warning code) and wt (warning type)
- update a global warnings_list with warning_info elements
- create a class hierarchy below BorgWarning class similar to Error class
- diff: change harmless warnings about speed to rc == 0
- delete --force --force: change harmless warnings to rc == 0

Also:

- have BackupRaceConditionError as a more precise subclass of BackupError
2024-02-14 01:26:12 +01:00
Thomas Waldmann b18e613627
get rid of some rare error classes, use RTError instead 2024-02-13 23:44:02 +01:00
Thomas Waldmann 0504dee0d9
fix dealing with remote repo Locking Exceptions
previously, this was handled in RPCError handler and always resulted in rc 2.

now re-raise Lock Exceptions locally, so it gives rc 2 (legacy) or 7x (modern).
2024-02-13 23:33:30 +01:00
Thomas Waldmann cb8b718a96
refactor set_ec usage
- msgpack version check: raise Error instead of calling set_ec
2024-02-13 23:16:46 +01:00
Thomas Waldmann bec02a36c8
use print_warning also in borg delete ::archive --force --force 2024-02-13 23:13:25 +01:00
Thomas Waldmann 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22:58:02 +01:00
Thomas Waldmann 1b09d0efd7
BORG_EXIT_CODES=modern can be set to get more specific process exit codes
If not set, it will default to "legacy" (always return 2 for errors).

This commit only changes the Error exception class and its subclasses.

The more specific exit codes need to be defined via .exit_mcode in the subclasses.
2024-02-13 19:53:17 +01:00
Thomas Waldmann 48afc4c519
requirements are defined in pyproject.toml 2024-02-09 17:37:42 +01:00
TW a4c8d52ca0
Merge pull request #8086 from ThomasWaldmann/index-check-value-errors-master
check: fix return code for index entry value discrepancies
2024-02-09 02:29:46 +01:00
TW 03e4494d84
Merge pull request #8084 from ThomasWaldmann/init-message-master
init: better borg key export instructions
2024-02-09 02:29:32 +01:00
Thomas Waldmann f43c1f56e9
check: fix return code for index entry value discrepancies
Also: use ERROR loglevel for these (not WARNING).

A different amount of index entries was already logged as error
and led to "error_found = True" in repository.check.

Different values in the rebuilt index vs. the on-disk index were
only logged on warning level, but did not lead to error_found = True.

Guess there is no reason why these should not be errors and lead to
error_found = True, so this was fixed in this commit.

Minor related change: change report_error function args, so it can be
called like logger.error - including giving a format AND args.
2024-02-09 00:43:06 +01:00
Thomas Waldmann 08bf0f741c
init: better borg key export instructions 2024-02-09 00:33:06 +01:00
Thomas Waldmann b6a23ee1bc
implement "borg version", fixes #7829
Additional new command "borg -r <REPO> version" which shows client and server version.
2024-02-09 00:16:29 +01:00
Thomas Waldmann ba2e8f2dec
borg.logger: use same method params as python logging 2024-01-15 21:40:27 +01:00
TW 812eb352f6
Merge pull request #7955 from ThomasWaldmann/improve-session-key-gen-master
crypto: use a one-step kdf for session keys, fixes #7953
2024-01-04 18:42:22 +01:00
kmille 865de9fcee
improve docs for borg with-lock (#8024)
docs: add example for borg with-lock
2024-01-03 23:42:29 +01:00
Thomas Waldmann e1fbd7d42e
fix mypy complaints 2024-01-02 20:57:42 +01:00
Thomas Waldmann 6720ab3aab
move conftest.py to src/borg/testsuite, see #6386
there, it will be packaged and installed, so
that when one runs the testsuite after installing
the pypi package, it will find the conftest.py.
2024-01-02 20:39:14 +01:00
Thomas Waldmann 73284db53f
PATH: do not accept empty strings, fixes #4221 2024-01-02 19:17:55 +01:00
Thomas Waldmann a4602c6f61
remove unused hkdf_hmac_sha512 and related tests 2023-12-02 20:35:14 +01:00
Thomas Waldmann 64ce6d5923
crypto: use a one-step kdf for session keys, fixes #7953
also:
- fixes, simplifies, speeds up _get_session_key
- convert sessionid memoryview to bytes before calling _get_cipher,
to avoid TypeError in (crypt_key + sessionid + domain) operation.
- add docstring and comments
2023-12-02 20:33:07 +01:00
Thomas Waldmann fe17ce2bba
fix typos
Thanks go to:
Author: Andrea Gelmini <andrea.gelmini@gelma.net>
2023-12-01 21:58:26 +01:00
Thomas Waldmann 2d86b7e1ac
add type annotation for mypy 2023-11-18 18:31:43 +01:00
Thomas Waldmann 046f9fe392
LockRoster.modify: no KeyError if element was already gone, fixes #7937
The intention of LockRoster.modify(key, REMOVE) is to remove self.id.

Using set.discard will just ignore it if self.id is not present there anymore.

Previously, using set.remove triggered a KeyError that has been frequently
seen in tracebacks of teardowns involving Repository.__del__ and Repository.__exit__.

I added a REMOVE2 op to serve one caller that needs to get the KeyError if
self.id was not present.

Thanks to @herrmanntom for the workaround!
2023-11-18 17:39:30 +01:00
Thomas Waldmann f3ddaaf001
create --*-from-command: run subcommands with a clean environment, fixes #7916
When borg invokes a system command, it needs to prepare the environment
for that. This is especially important when using a pyinstaller-made
borg fat binary that works with a modified env var LD_LIBRARY_PATH -
system commands may crash with that.

borg already had calls to prepare_subprocess_env at some places (e.g.
when invoking ssh for the remote repo connection), but they were
missing for:

borg create --content-from-command ...
borg create --paths-from-command ...
2023-11-09 00:04:03 +01:00
TW e431b838f4
Merge pull request #7910 from ThomasWaldmann/fix-shadow-index-master
Fix shadow index (master)
2023-11-05 20:17:48 +01:00
TW fba3e388aa
Merge pull request #7909 from ThomasWaldmann/sort-by-aliases-master
--sort-by: support "archive" as alias of "name", fixes #7873
2023-11-05 19:08:25 +01:00
Thomas Waldmann 57f3dd1dae
check --repair: recreate shadow index, see #6687
before this fix, borg check --repair just created an
empty shadow index, which can lead to incomplete
entries if entries are added later.

and such incomplete (but present) entries can lead to
compact_segments() resurrecting old PUTs by accidentally
dropping related DELs.
2023-11-05 18:45:22 +01:00
Thomas Waldmann 7892e4212b
check --repair: test if shadow index is recreated
still failing here, because it is not.
2023-11-05 18:41:31 +01:00