Commit Graph

213 Commits

Author SHA1 Message Date
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 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 9de07ebd46
update "modern" error RCs (docs and code) 2024-02-13 22:58:02 +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 2d86b7e1ac
add type annotation for mypy 2023-11-18 18:31:43 +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 5d28992b51
shadow index: add more comments 2023-11-05 18:30:00 +01:00
Thomas Waldmann 3ba533ac50
shadow index updates: simplify and more comments
no functional change here.
2023-11-05 18:28:48 +01:00
Thomas Waldmann 6d9513f507
update shadow index when doing a double-put, fixes #5661
this fixes the test added in previous commit (avoids
that the PUT reappears after index rebuild).
2023-11-05 18:25:06 +01:00
Thomas Waldmann 5013121bd8
fix E501 2023-07-26 01:24:20 +02:00
Thomas Waldmann 3aec98ada9
remote logging/progress: use callback to send queued records, fixes #7662 2023-06-22 20:09:29 +02:00
Eric Wolf e683c80c75
replace `LRUCache` internals with `OrderedDict`
Replacing the internals should make the implementation faster
and simpler since the order tracking is done by the `OrderedDict`.

Furthermore, this commit adds type hints to `LRUCache` and
renames the `upd` method to `replace` to make its use more clear.
2023-06-10 20:57:32 +02:00
Thomas Waldmann 6ae23bc0d7
fix typo 2023-05-29 15:04:30 +02:00
nain 4a7a5b2253 Add function to clear empty directories at end of compact process.
Compact moves data to new segments, and then removes the old segments.
When enough segments are moved, directories holding the now cleared segments
may thus become empty.

With this commit any empty directories are cleared after segments compacting.
Fixes #6823
2023-05-28 01:48:32 -04:00
nain ffe237ce0c unify scanning and listing of segment dirs / segment files and apply good practices
+ os.scandir instead of os.listdir
  Improved speed and added flexibility with attributes (name, path, is_dir(), is_file())
+ use is_dir / is_file to make sure  we're reading only dirs / files respectively
+ Filtering to particular start, end index range built in
+ Move value bounds of segment (index) into constants module and use them instead

Resolves #7597

(forward patch from commits c9f35a16e9bf9e7073c486553177cef79ff1cb06^..edb5e749f512b7737b6933e13b7e61fefcd17bcb)
2023-05-27 07:54:32 -04:00
Thomas Waldmann e02d9edc34
remove nonce management, related repo methods
not needed for borg2 repos (we derive a new session key for each borg
invocation and start counting from 0).

also not needed for borg 1.x repos because we only read them (borg transfer)
and won't write new encrypted data to them.
2023-05-11 17:51:49 +02:00
Thomas Waldmann 52793be923
pyupgrade --py39-plus ./**/*.py 2023-04-02 02:14:54 +02:00
Josh Soref c9848e9814 spelling: nonexistent
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-01-12 09:36:03 -05:00
Paul D 253d8e8d4e Docs grammar fixes
joined split infinitives, and relocated adverbs appropriately.
2022-12-29 22:26:54 +00:00
Paul D a85b643866 Docs grammar fixes.
One cannot "to not x", but one can "not to x".
Avoiding split infinitives gives the added bonus that machine
translation yields better results.

setup (n/adj) vs set(v) up. We don't "I setup it" but "I set it up".

Likewise for login(n/adj) and log(v) in, backup(n/adj) and back(v) up.
2022-12-29 00:01:48 +00:00
Franco Ayala ab465a75d4
Adding used storage quota to borg info (#7121) 2022-12-24 01:55:47 +01:00
Thomas Waldmann 8747644540
remove --save-space
this option did not change behaviour since longer,
we only had kept it for API compatibility.

as a borg2 repo server won't have old clients talking to it,
we can safely remove this everywhere now.
2022-12-17 16:48:54 +01:00
Rayyan Ansari 2a8cacf517 repository: cleanup(): close segment before unlinking
On Windows, trying to delete a file that is already open raises an exception.

Docs:
https://docs.python.org/3/library/os.html#os.remove
2022-11-11 18:21:11 +00:00
Rayyan Ansari 62341673c1 repository: use os.replace instead of os.rename
On Windows, os.rename raises an exception if the destination file already exists, unlike os.replace which replaces the destination file.

Docs:
https://docs.python.org/3/library/os.html#os.rename
https://docs.python.org/3/library/os.html#os.replace
2022-11-10 17:56:45 +00:00
TW c29d4a096b
Hashindex header work, fixes #6960 (#7064)
support reading new, improved hashindex header format, fixes #6960

Bit of a pain to work with that code:
- C code
- needs to still be able to read the old hashindex file format,
- while also supporting the new file format.
- the hash computed while reading the file causes additional problems because
  it expects all places in the file get read exactly once and in sequential order.
  I solved this by separately opening the file in the python part of the code and
  checking for the magic.
  BORG_IDX means the legacy file format and legacy layout of the hashtable,
  BORG2IDX means the new file format and the new layout of the hashtable.

Done:
- added a version int32 directly after the magic and set it to 2 (like borg 2).
  the old header had no version info, but could be denoted as version 1 in case
  we ever need it (currently it decides based on the magic).
- added num_empty as indicated by a TODO in count_empty, so it does not need a
  full hashtable scan to determine the amount of empty buckets.
- to keep it simpler, I just filled the HashHeader struct with a
  `char reserved[1024 - 32];`
  1024 being the desired overall header size and 32 being the currently used size.
  this alignment might be useful in case we mmap() the hashindex file one day.
2022-10-02 14:35:21 +02:00
Thomas Waldmann b3c7d8f5f3 repository.scan: fix start_offset
start_offset (from state) is only valid for start_segment, otherwise we must use 0.
2022-09-20 21:25:36 +02:00
Thomas Waldmann c4e54ca44e repository.scan: use same end_segment within same scan
achieved by putting it into the state that is now used instead of the marker.
2022-09-19 21:14:25 +02:00
Thomas Waldmann 49a4884cfe repository.scan: do not use chunkid as marker, but (segment, offset)
when using .scan(limit, marker), we used to use the last chunkid from
the previously returned scan result to remember how far we got and
from where we need to continue.

as this approach used the repo index to look up the respective segment/offset,
it was problematic if the code using scan was re-writing the chunk to
a new segment/offset, updating the repo index (e.g. when recompressing a chunk)
and basically destroying the memory about from where we need to continue
scanning.

thus, directly returning (segment, offset) as marker is easier and solves this issue.
2022-09-19 12:03:13 +02:00
Thomas Waldmann ce08f92090 repository.scan: only iterate over committed chunks
otherwise, if we scan+get+put (e.g. if we read/modify/write chunks to
recompress them), it would scan past the last commit and run into the
newly written chunks (and potentially never terminate).
2022-09-19 11:05:07 +02:00
Thomas Waldmann 78de77e67a check: fix uninitialised variable if repo is completely empty, fixes #7034 2022-09-17 20:54:13 +02:00
TW 36e852457a
Merge pull request #6992 from ThomasWaldmann/separate-encrypted-metadata
Separate encrypted metadata
2022-09-09 21:16:13 +02:00
Thomas Waldmann 106abbe4d9 new read_data param for repository.get() and .get_many()
True (default): return full chunk (client can decrypt meta and data)

False: return enough so client can decrypt only the meta
2022-09-08 18:31:56 +02:00
Thomas Waldmann 74ffceabf4 simplify: read_data param of io.read() is not used (yet) 2022-09-08 13:17:59 +02:00
Thomas Waldmann b64427c480 simplify: iter_objects always returns (..., size, data)
data might be None (if read_data is False).

also removed the include_data argument, not needed any more.
2022-09-08 12:48:39 +02:00
Thomas Waldmann 062c860260 repository: start messages with uppercase letters. 2022-09-01 22:28:00 +02:00
Thomas Waldmann 90ca04f535 repository api: flags support, fixes #6982
- .list: only return IDs for objects where flags & mask == value.
- .flags(_many) (new) to set/query flags
2022-08-22 18:16:59 +02:00
Thomas Waldmann 15d56b2ff7 minor cleanup: fix typos and punctuation in comments 2022-08-21 11:36:27 +02:00
Thomas Waldmann 578639b35e move lrucache module to borg.helpers 2022-08-13 22:02:04 +02:00
Thomas Waldmann 9beaced33c move manifest module from helpers to borg.manifest 2022-08-13 21:55:12 +02:00
Thomas Waldmann ade08ce842 use timezones
- timezone aware timestamps
- str representation with +HHMM or +HH:MM
- get rid of to_locatime
- fix with_timestamp
- have archive start/end time always in local time with tz or as given
- idea: do not lose tz information

then we know when a backup was made and even from
which timezone it was made. if we want to compute
utc, we can do that using these infos.

this makes a quite nice archives list, with timestamps
as expected (in local time with timezone info).

at some places we just enforce utc, like for the
repo manifest timestamp or for the transaction log,
these are usually not looked at by the user.
2022-08-13 18:31:22 +02:00
Thomas Waldmann bab68a8d25 use py37+ datetime.isoformat / .fromisoformat
since python 3.7, .isoformat() is usable IF timespec != "auto"
is given ("auto" [default] would be as evil as before, sometimes
formatting with, sometimes without microseconds).

also since python 3.7, there is now .fromisoformat().
2022-08-11 21:18:56 +02:00
KN4CK3R 00aca33ba6
Forwardport: repository: add debug logging for issue (#6918) (#6946)
repository: add debug logging for issue #6687
2022-08-06 23:38:30 +02:00
Thomas Waldmann 7bc7f01342 remove remainders of attic legacy
we expect that everybody has upgraded to borg
using borg 1.2.x or older, thus we do not need
to care about attic repos any more in borg2.
2022-07-13 16:55:29 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann b0b5a2fd27 add repository.info(), giving some basic repo infos
there was no way to tell the repository version for a remote repo.
borg 2 needs that to reject doing most operations with an old repo,
except the stuff needed for borg transfer.
2022-06-30 23:55:51 +02:00
Thomas Waldmann 8ebdb0b024 support repo version 1 also, fixes #6811
v2 is the default repo version for borg 2.0.
v1 repos must only be used in a read-only way, e.g. for
--other-repo=V1_REPO with borg init and borg transfer!
2022-06-29 17:31:50 +02:00
Thomas Waldmann dbae8e60eb remove borg upgrade 2022-06-26 00:25:44 +02:00
Thomas Waldmann 3fbb297fd7 compact: remove --cleanup-commits
this was a one-time fix only needed for borg 1.2.

users are expected to use borg 1.2 to cleanup the commits.
2022-06-26 00:07:07 +02:00
Thomas Waldmann e0c64629d1 Merge branch 'master' into borg2
strange conflicts, automated patches seemed to not have applied correctly.
also had to fix some stuff manually, tests were failing.
2022-06-23 11:25:01 +02:00
Thomas Waldmann e5ea016115 repository: set/query flags, iteration over flagged items (NSIndex)
use this to query or set/clear flags in the "extra" word.

also: remove direct access to the "extra" word, adapt tests.
2022-06-14 14:48:56 +02:00