Commit Graph

306 Commits

Author SHA1 Message Date
Thomas Waldmann 7878a34fd4
add get_runtime_dir / BORG_RUNTIME_DIR, tests, docs 2023-06-06 11:58:48 +02:00
David Rambo 4efc7cd0bd Add support and tests for shell-style alternatives
Code review fixes

Remove empty line
2023-05-31 15:38:05 -07:00
Thomas Waldmann c3a4568870
channel progress output via logging system
- simplify progress output (no \r, no terminal size related tweaks)
- emit progress output via the logging system (so it does not use stderr
  of borg serve)
- progress code always logs a json string, the json has all needed
  to either do json log output or plain text log output.
- use formatters to generate plain or json output from that.
- clean up setup_logging
- use a StderrHandler that always uses the **current** sys.stderr
- tweak TestPassphrase to not accidentally trigger just because of seeing 12 in output
2023-05-29 22:40:47 +02:00
Thomas Waldmann 0be545dc45
remove ProgressIndicatorEndless (not used) 2023-05-29 22:40:45 +02:00
Thomas Waldmann b8d49a0274
put security infos into data dir, fixes #5760 2023-05-18 12:48:45 +02:00
Thomas Waldmann 05bf29f504
fix SortBySpec validator 2023-04-12 01:21:43 +02:00
Thomas Waldmann 0f923c8c4a
fix FilesCacheMode validator 2023-04-12 01:18:05 +02:00
Thomas Waldmann 6d38530ff1
fix ChunkerParams validator and tests 2023-04-12 01:15:46 +02:00
Thomas Waldmann 7a2c757c69
rlist: add size and nfiles to format keys, fixes #6086 2023-04-07 16:37:17 +02:00
Thomas Waldmann 355a50225f
ArchiveFormatter.get_meta: add default value argument 2023-04-07 14:23:43 +02:00
TW ffea8a0f25
Merge pull request #7487 from ThomasWaldmann/pyupgrade-py39-plus
pyupgrade --py39-plus ./**/*.py
2023-04-02 23:02:07 +02:00
Thomas Waldmann 3dd14f4855
ProgressIndicatorPercent: fix space computation for wide chars, fixes #3027
needs to use swidth() in case there are wide chars (like CJK)
in the left part of the msg (e.g. an archive name).
2023-04-02 21:57:02 +02:00
Thomas Waldmann 52793be923
pyupgrade --py39-plus ./**/*.py 2023-04-02 02:14:54 +02:00
nain-F49FF806 dfef2b9092
fix config/cache dir compatibility issues, fixes #7445 (#7448)
fix config dir compatibility issue, fixes #7445

- add tests
- make sure the result of get_cache_dir matches pre and post #7300 where desired
- harmonize implementation of config_dir_compat and cache_dir_compat tests

Co-authored-by: nain <126972030+F49FF806@users.noreply.github.com>
2023-03-30 00:24:42 +02:00
Thomas Waldmann 1ab90b339e
allow msgpack 1.0.5 also 2023-03-09 22:26:38 +01:00
Michael Deyaso 2c232449b0
Modified Item.pyx to include diffs in ctime and mtime (#7335)
diff: include changes in ctime and mtime, fixes #7248

also:
- sort JSON output alphabetically
- add --content-only to ignore metadata changes

Co-authored-by: Michael Deyaso <mdeyaso@fusioniq.io>
2023-03-06 23:18:36 +01:00
Thomas Waldmann 7f973a5b34
implement "fail" chunker for testing purposes
--chunker-params=fail,4096,rrrEErrrr means:
- cut chunks of 4096b fixed size (last chunk in a file can be less)
- read chunks 0, 1 and 2 successfully
- error at chunk 3 and 4 (simulated OSError(errno.EIO))
- read successfully again for the next 4 chunks

Chunks are counted inside the chunker instance, starting
from 0, always increasing while the same instance is used.

Read chunks as well as failed chunks count up by 1.
2023-02-13 17:15:45 +01:00
Rayyan Ansari 03a27654e0 parseformat: remove Windows-specific hack
This fixes the rest of the tests.
2023-02-11 16:32:19 +00:00
Thomas Waldmann bde0f11e1e
get_security_dir: legacy=False default 2023-02-04 00:35:04 +01:00
Thomas Waldmann 1d4810af23
get_keys_dir: legacy=False default 2023-02-04 00:35:03 +01:00
Thomas Waldmann b06dd1c66c
get_config_dir: legacy=False default 2023-02-04 00:35:01 +01:00
Thomas Waldmann ebcda6f0a5
get_cache_dir: legacy=False default 2023-02-04 00:34:57 +01:00
Thomas Waldmann 424be763b2
get_base_dir: legacy=False default 2023-02-04 00:34:54 +01:00
Thomas Waldmann fddf6afded
get_*_dir: make legacy=... kwarg only
it's better readable.
2023-02-04 00:34:45 +01:00
Thomas Waldmann 8379ecefaa
deal with BORG_BASE_DIR 2023-02-04 00:34:26 +01:00
Rayyan Ansari f2452aef2a
helpers: use platformdirs on win32 2023-02-03 17:46:49 +01:00
Thomas Waldmann a863249394
fs.py: fix bug in f-string - thanks mypy! 2023-01-30 15:54:50 +01:00
Michael Deyaso b2654bc17d
Support for date-based matching during archive listing (#7272)
check --archives: add --newer/--older/--newest/--oldest, fixes #7062

Options accept a timespan, like Nd for N days or Nm for N months.

Use these to do date-based matching on archives and only check some of them,
like: borg check --archives --newer=1m --newest=7d

Author: Michael Deyaso <mdeyaso@fusioniq.io>
2023-01-23 15:00:05 +01:00
Thomas Waldmann bf667170a7
ArchiveItem.cmdline list-of-str -> .command_line str, fixes #7246
Same change for .recreate_cmdline -> .recreate_command_line .

JSON output key "command_line":
borg 1.x: sys.argv [list of str]
borg 2: shlex.join(sys.argv) [str]
2023-01-20 00:19:00 +01:00
Thomas Waldmann 249189e04e
refactor: reuse code from remove_surrogates 2023-01-19 20:58:58 +01:00
Thomas Waldmann b3da7d0e72
make sure hostname and username have no surrogate escapes
if they are present, process them through json_text().
this replaces s-e by "?" for the key and puts the binary
representation into key_b64, if needed.

likely this is rarely needed.
2023-01-19 20:46:40 +01:00
Thomas Waldmann 9460da42d1
use local time / local timezone to output timestamps, fixes #7283
"ls" and also "tar" show timestamps as local time.
borg now does the same, but also shows the local tzoffset.

this also affects JSON output.
2023-01-19 03:36:46 +01:00
TW c8fe49dcb7
Merge pull request #7276 from ThomasWaldmann/symlink-target
Item: symlinks: rename .source to .target, fixes #7245
2023-01-18 17:05:25 +01:00
Thomas Waldmann 88b9868159
shellpattern: add license, use copyright/license markup 2023-01-18 15:45:13 +01:00
Thomas Waldmann 1672aee031
Item: symlinks: rename .source to .target, fixes #7245
Also, in JSON:
- rename "linktarget" to "target" for symlinks
- remove "source" for symlinks
2023-01-16 20:28:25 +01:00
Thomas Waldmann 262812e76f
get_item_data: do not require item.uid/gid, see #7249
if uid is not present, use None.
if gid is not present, use None.
2023-01-16 18:17:03 +01:00
Thomas Waldmann 491f898612
borg2 archive names and comments are always pure unicode 2023-01-16 17:45:48 +01:00
Thomas Waldmann e63cfcd708
json output: use text_to_json, fixes #6151
item: path, source, user, group

for non-unicode stuff borg 1.2 had "bpath".

now we have:
path - unicode approximation (invalid stuff replaced by ?)
path_b64 - base64(path_bytes)  # only if needed

source has the same issue as path and is now covered also.

user and group are usually unicode or even pure ASCII,
but we rather are cautious and cover them also.
2023-01-16 17:45:34 +01:00
Thomas Waldmann 32d430a1b0
implement text_to_json / binary_to_json, see #6151
binary bytes:
- json_key = <key>_b64
- json_value == base64(value)

text (potentially with surrogate escapes):
- json_key1 = <key>
- json_value1 = value_text (s-e replaced by ?)
- json_key2 = <key>_b64
- json_value2 = base64(value_binary)

json_key2/_value2 is only present if value_text required
replacement of surrogate escapes (and thus does not represent
the original value, but just an approximation).
value_binary then gives the original bytes value (e.g. a
non-utf8 bytes sequence).
2023-01-16 17:45:27 +01:00
Paul D 253d8e8d4e Docs grammar fixes
joined split infinitives, and relocated adverbs appropriately.
2022-12-29 22:26:54 +00:00
Rayyan Ansari 66a407ff9f Use \n for the {NL} format specifier
\n is automatically converted on write to the platform-dependent os.linesep.
Using os.linesep instead of \n means that on Windows, the line ending becomes "\r\r\n".
Also switches mentions of {LF} to {NL} in code and docs.
2022-12-18 14:05:24 +00:00
Rayyan Ansari 5e8452a705 archiver: create_cmd: do not add preexec_fn on Windows
The preexec_fn argument of Popen is not supported on Windows.
2022-12-18 14:00:35 +00:00
Thomas Waldmann a475227e18
use archivename_validator everywhere
also: simplify, reuse code from text_validator.
2022-12-15 22:54:46 +01:00
Thomas Waldmann b9dc2be661
remove support for bpath placeholder
this needs to get done differently later, maybe base64 for json output.
2022-12-12 19:39:52 +01:00
Thomas Waldmann 1e2741ad3d
remove support for barchive placeholder
not needed any more as the archive name is now validated pure text.
2022-12-12 19:10:58 +01:00
Thomas Waldmann 1517db07ec
remove support for bcomment placeholder
not needed any more as the comment is now validated pure text.
2022-12-12 18:55:14 +01:00
Thomas Waldmann 99c6afbc61
add generic text and comment validator 2022-12-12 18:01:07 +01:00
Thomas Waldmann fe2b2bc007
archive names: validate more strictly, fixes #2290
we want to be able to use an archive name as a directory name,
e.g. for the FUSE fs built by borg mount.

thus we can not allow "/" in an archive name on linux.

on windows, the rules are more restrictive, disallowing
quite some more characters (':<>"|*?' plus some more).
we do not have FUSE fs / borg mount on windows yet, but
we better avoid any issues.
we can not avoid ":" though, as our {now} placeholder
generates ISO-8601 timestamps, including ":" chars.

also, we do not want to have leading/trailing blanks in
archive names, neither surrogate-escapes.

control chars are disallowed also, including chr(0).
we have python str here, thus chr(0) is not expected in there
(is not used to terminate a string, like it is in C).
2022-12-12 17:05:01 +01:00
Thomas Waldmann 15139a80c9
bugfix: switch archive timestamps to utc
we use utc for file timestamps and manifest timestamp,
so let's use utc for archives also.
2022-12-04 10:55:20 +01:00
Thomas Waldmann 1f859c9f17
refactor: get archive timestamps via archive_ts_now() 2022-12-04 10:55:17 +01:00
Thomas Waldmann 87e597011a
bugfix: file timestamps should use tz-aware utc datetime objs
the UNIX time used for timestamp is seconds since 1.1.1970,
in UTC. thus, the natural way to represent it is with a
tz-aware utc datetime object.

but previously (in borg 1.x), they used naive datetime
objects and localtime.
2022-12-04 09:07:29 +01:00
Thomas Waldmann c343673ab5
bugfix: do no assume hardlink_master=True if not present, see #7175
this would produce unneeded item.hlid attributes
for fifos, char and block devices when transferring /
upgrading from faulty borg 1.x archives.
2022-11-28 23:57:59 +01:00
Thomas Waldmann f5f38a1fbd
remove python < 3.7 compatibility code
not supported any more in master and 1.2-maint branches.
2022-11-06 18:22:56 +01:00
Thomas Waldmann 287907b218 bsdflags cleanup, #6908
https://github.com/borgbackup/borg/issues/6908#issuecomment-1224839170
2022-09-14 11:24:50 +02:00
Thomas Waldmann d3a2d831b7 refactor replace_placeholders, fixes #6966
fix replacing placeholders in archive name, --comment and --glob-archives values (even if overridden by other options like
--timestamp).

add test.
2022-09-09 23:28:34 +02:00
Thomas Waldmann fa986a9f19 repoobj: add a layer to format/parse repo objects
borg < 2:

obj = encrypted(compressed(data))

borg 2:

obj = enc_meta_len32 + encrypted(msgpacked(meta)) + encrypted(compressed(data))

handle compr / decompr in repoobj

move the assert_id call from decrypt to RepoObj.parse

also:
- for AEADKeyBase, add a dummy assert_id (not needed here)
- only test assert_id for other if not AEADKeyBase instance
- remove test_getting_wrong_chunk. assert_id is called elsewhere
  and is not needed any more anyway with the new AEAD crypto.
- only give manifest (includes key, repo, repo_objs)
- only return manifest from Manifest.load (includes key, repo, repo_objs)
2022-09-04 00:49:38 +02:00
Thomas Waldmann 403ff07dde move nanorst module to borg.helpers 2022-08-13 22:10:13 +02:00
Thomas Waldmann ecd7bce5b8 move shellpattern module to borg.helpers 2022-08-13 22:03:44 +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 ded384929d move tar related code to borg.archiver.tar 2022-08-13 21:31:41 +02:00
Thomas Waldmann 22804f05f9 move prune related code to borg.archiver.prune 2022-08-13 20:59:18 +02:00
Thomas Waldmann 4ab07b6acb create/recreate/import-tar --timestamp: default to local timezone
if you want to give UTC, just append: +00:00
2022-08-13 19:17:10 +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
Thomas Waldmann 4d570497be ctrl-c must not kill other subprocesses, fixes #6912
There are some other places with subprocesses:

- borg create --content-from-command
- borg create --paths-from-command
- (de)compression filter process of import-tar / export-tar
2022-08-06 23:37:38 +02:00
Thomas Waldmann 0ab82d57e4 ctrl-c must not kill the ssh subprocess, fixes #6912 2022-08-06 23:27:00 +02:00
Thomas Waldmann 52c47bd546 use a custom mkstemp with mode support, fixes #6933, fixes #6400
hopefully this is the final fix.

after first fixing of #6400 (by using os.umask after mkstemp), there
was a new problem that chmod was not supported on some fs.

even after fixing that, there were other issues, see the ACLs issue
documented in #6933.

the root cause of all this is tempfile.mkstemp internally using a
very secure, but hardcoded and for our use case problematic mode
of 0o600.

mkstemp_mode (mosty copy&paste from python stdlib tempfile module +
"black" formatting applied) supports giving the mode via the api,
that is the only change needed.

slightly dirty due to the _xxx imports from tempfile, but hopefully
this will be supported in some future python version.
2022-08-04 14:41:00 +02:00
Thomas Waldmann 15cb54f623 list: fix {flags:<WIDTH>} formatting, fixes #6081
item.bsdflags is either not present or an int, thus we default to 0 (== no flags) if not present.
2022-07-29 10:44:37 +02:00
Thomas Waldmann b8e48c5036 mypy: fixes / annotations 2022-07-15 14:54:48 +02:00
Thomas Waldmann 366ef73f88 mypy: rename yes module to yes_no to avoid name collision 2022-07-15 14:46:18 +02:00
Thomas Waldmann ff411b5d98 move serve command to archiver.serve 2022-07-09 15:13:12 +02:00
Thomas Waldmann 7957af562d blacken all the code
https://black.readthedocs.io/
2022-07-06 16:34:38 +02:00
Thomas Waldmann 350393c9fd remove unused imports 2022-07-05 00:05:07 +02:00
Thomas Waldmann 6888d5dcb2 remove -P (aka --prefix) option, fixes #6806
-a (aka --glob-archives) can be used for same purpose and is more powerful.
2022-07-02 20:52:41 +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 f8d2024578 borg recreate -a ARCHIVE_GLOB ... 2022-06-20 20:17:29 +02:00
Thomas Waldmann 7dbf125083 Location: remove archive name 2022-06-16 14:18:47 +02:00
Thomas Waldmann 281bbbc16b fix tests and benchmarks 2022-06-16 14:18:39 +02:00
Thomas Waldmann 0f0cd24354 if --(other-)repo option is not given, use default from environment
remove tests composing a repo+archive location with repo from env
and location from cli.
2022-06-16 14:14:54 +02:00
Thomas Waldmann 1bf2a6a240 remove archive checks from location_validator, use --other-repo 2022-06-15 17:07:42 +02:00
Thomas Waldmann ba1f8926cc secure_erase: avoid collateral damage, fixes #6768
if a hardlink copy of a repo was made and a new repo config
shall be saved, do NOT fill in random garbage before deleting
the previous repo config, because that would damage the hardlink
copy.
2022-06-13 15:57:01 +02:00
Thomas Waldmann 822aefc7b0 re-add dsize placeholder 2022-06-12 17:15:13 +02:00
Thomas Waldmann b726aa5665 remove csize support from get_size 2022-06-12 15:48:33 +02:00
Thomas Waldmann b9f9623a6d prepare to remove csize (set it to 0 for now) 2022-06-12 15:48:33 +02:00
Thomas Waldmann d4ee968b07 use borg 2.0 to refer to this, not 1.3
also, some type conversions are now done in update_internal once,
not in the decode methods of the classes in item.pyx.
2022-06-09 18:13:40 +02:00
Thomas Waldmann f2b085787b Item: disallow None value for .user/group/chunks/chunks_healthy
If we do not know the value, just do not have that key/value pair in the item.
2022-06-09 17:57:28 +02:00
Thomas Waldmann 7b138cc710 Item: convert timestamps once, get rid of bigint code 2022-06-09 17:57:28 +02:00
Thomas Waldmann 33444be926 more str vs bytes fixing 2022-06-09 17:57:28 +02:00
Thomas Waldmann 8e87f1111b cleanup msgpack related str/bytes mess, fixes #968
see ticket and borg.helpers.msgpack docstring.

this changeset implements the full migration to
msgpack 2.0 spec (use_bin_type=True, raw=False).

still needed compat to the past is done via want_bytes decoder in borg.item.
2022-06-09 17:57:28 +02:00
Thomas Waldmann f8dbe5b542 cleanup msgpack related str/bytes mess, see #968
see ticket and borg.helpers.msgpack docstring.
2022-06-09 17:57:28 +02:00
Thomas Waldmann 32a3601e4a compute hlid from inode / device 2022-06-09 17:49:16 +02:00
Thomas Waldmann a970f000b0 allow msgpack 1.0.4, fixes #6716 2022-06-03 10:03:49 +02:00
Elmar Hoffmann fd34fa2d02 use relative imports
Use relative imports where trivially possible for more consistency and to
avoid using the borg module name explicitly.
2022-05-29 09:36:52 +02:00
Elmar Hoffmann c34df51e3e import IntegrityError used as base class with according name
This not only brings code style in line with the other helpers that do the
same thing this way, but also does away with an unnecessary absolute import
using the borg module name explicitly.
2022-05-28 16:07:20 +02:00
Thomas Waldmann 61299d23db Revert "Remove scp syntax for locations (#6697)"
This reverts commit 1b4b84dfd8.
2022-05-18 17:31:10 +02:00
Thomas Waldmann 6bfdb3f630 refactor hardlink_master processing globally
borg now has the chunks list in every item with content.
due to the symmetric way how borg now deals with hardlinks using
item.hlid, processing gets much simpler.

but some places where borg deals with other "sources" of hardlinks
still need to do some hardlink management:
borg uses the HardLinkManager there now (which is not much more
than a dict, but keeps documentation at one place and avoids some
code duplication we had before).

item.hlid is computed via hardlink_id function.

support hardlinked symlinks, fixes #2379
as we use item.hlid now to group hardlinks together,
there is no conflict with the item.source usage for
symlink targets any more.

2nd+ hardlinks now add to the files count as did the 1st one.
for borg, now all hardlinks are created equal.
so any hardlink item with chunks now adds to the "file" count.

ItemFormatter: support {hlid} instead of {source} for hardlinks
2022-05-18 14:20:01 +02:00
Thomas Waldmann 7903dad183 transfer: convert timestamps int/bigint -> msgpack.Timestamp, see #2323
Timestamp scales to 64 or 96bit serialization formats, that should be enough for everybody.

We use this in archived items and also in the files cache.
2022-05-18 14:20:01 +02:00
Emil M George 1b4b84dfd8
Remove scp syntax for locations (#6697)
remove scp syntax support from cli and from Location parser, add note about converting scp-style URLs to ssh-style, fixes #6691
2022-05-15 21:55:19 +02:00
Thomas Waldmann 18eb696a17 fix create_filter_process exception handler, fixes #6681
if cmd was falsy (e.g. None), there is no proc.
then, if "yield stream" raises an exception, the exception handler crashed at "proc.kill()".
2022-05-08 18:46:13 +02:00