Repository: borgbackup/borg

Issue:
Borg config --list does not show last_segment_checked
## Have you checked borgbackup docs, FAQ, and open Github issues?

Yes

## Is this a BUG / ISSUE report or a QUESTION?

BUG

## System information. For client/server mode post info for both machines.

1.2.0a8 / also master

#### Full borg commandline that lead to the problem (leave away excludes and passwords)

`borg config --list /path/to/repo`

## Describe the problem you're observing.

If a partial check has started and has been stopped due to timeout, the config file contains the `last_segment_checked` key with an int value.
You can verify that with `borg config /path/to/repo last_segment_checked`, which prints the segment number.

Now try `borg config --list /path/to/repo`: The last_segment_checked is missing.

Reason: In source code of archiver.py `last_segment_checked` is not read when the list subcommand is executed.

I will create a PR for this.

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=h1) Report
> Merging [#5160](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=desc) into [master](https://codecov.io/gh/borgbackup/borg/commit/fae0b9b1eef4955352be1aa930d4a84b3158c256&el=desc) will **decrease** coverage by `0.30%`.
> The diff coverage is `50.00%`.

[![Impacted file tree graph](https://codecov.io/gh/borgbackup/borg/pull/5160/graphs/tree.svg?width=650&height=150&src=pr&token=LssEpmW3o4)](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #5160      +/-   ##
==========================================
- Coverage   83.93%   83.62%   -0.31%     
==========================================
  Files          37       37              
  Lines        9834     9839       +5     
  Branches     1636     1638       +2     
==========================================
- Hits         8254     8228      -26     
- Misses       1101     1126      +25     
- Partials      479      485       +6     
```


| [Impacted Files](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/borg/archiver.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvYXJjaGl2ZXIucHk=) | `80.73% <50.00%> (-0.06%)` | :arrow_down: |
| [src/borg/platform/\_\_init\_\_.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvcGxhdGZvcm0vX19pbml0X18ucHk=) | `72.00% <0.00%> (-12.00%)` | :arrow_down: |
| [src/borg/platform/xattr.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvcGxhdGZvcm0veGF0dHIucHk=) | `82.53% <0.00%> (-6.35%)` | :arrow_down: |
| [src/borg/xattr.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcveGF0dHIucHk=) | `48.83% <0.00%> (-3.49%)` | :arrow_down: |
| [src/borg/platform/base.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvcGxhdGZvcm0vYmFzZS5weQ==) | `77.58% <0.00%> (-3.45%)` | :arrow_down: |
| [src/borg/helpers/misc.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvaGVscGVycy9taXNjLnB5) | `77.02% <0.00%> (-2.03%)` | :arrow_down: |
| [src/borg/archive.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvYXJjaGl2ZS5weQ==) | `82.55% <0.00%> (-0.69%)` | :arrow_down: |
| [src/borg/repository.py](https://codecov.io/gh/borgbackup/borg/pull/5160/diff?src=pr&el=tree#diff-c3JjL2JvcmcvcmVwb3NpdG9yeS5weQ==) | `84.29% <0.00%> (-0.19%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=footer). Last update [fae0b9b...f5b3476](https://codecov.io/gh/borgbackup/borg/pull/5160?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

ThomasWaldmann: Well, I was not sure whether this should be changed, considering last_segment_checked is a rather internal thing that is maybe not interesting to read and maybe even bad if set to a wrong value.

OTOH, we can expect admins to be able to deal with it and they are allowed to shoot themselves in the feet. :-)

Patch:
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
index 0c3e2639..0d80a960 100644
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -1659,7 +1659,7 @@ def do_config(self, args, repository):
         def repo_validate(section, name, value=None, check_value=True):
             if section not in ['repository', ]:
                 raise ValueError('Invalid section')
-            if name in ['segments_per_dir', 'max_segment_size', 'storage_quota', ]:
+            if name in ['segments_per_dir', 'max_segment_size', 'storage_quota', 'last_segment_checked', ]:
                 if check_value:
                     try:
                         int(value)
@@ -1716,6 +1716,11 @@ def list_config(config):
                     if value is None:
                         raise Error('The repository config is missing the %s key which has no default value' % key)
                 print('%s = %s' % (key, value))
+            for key in ['last_segment_checked', ]:
+                value = config.get('repository', key, fallback=None)
+                if value is None:
+                    continue
+                print('%s = %s' % (key, value))
 
         if not args.list:
             if args.name is None:
@@ -4104,16 +4109,15 @@ def define_borg_mount(parser):
                                         '"borg help compression" command for details.')
         archive_group.add_argument('--recompress', metavar='MODE', dest='recompress', nargs='?',
                                    default='never', const='if-different', choices=('never', 'if-different', 'always'),
-                                   help='recompress data chunks according to `MODE` and ``--compression``. '
-                                        'Possible modes are '
-                                        '`if-different`: recompress if current compression is with a different '
-                                        'compression algorithm (the level is not considered); '
-                                        '`always`: recompress even if current compression is with the same '
-                                        'compression algorithm (use this to change the compression level); and '
-                                        '`never`: do not recompress (use this option to explicitly prevent '
-                                        'recompression). '
-                                        'If no MODE is given, `if-different` will be used. '
-                                        'Not passing --recompress is equivalent to "--recompress never".')
+                                   help='recompress data chunks according to ``--compression``. '
+                                        'MODE `if-different`: '
+                                        'recompress if current compression is with a different compression algorithm '
+                                        '(the level is not considered). '
+                                        'MODE `always`: '
+                                        'recompress even if current compression is with the same compression algorithm '
+                                        '(use this to change the compression level). '
+                                        'MODE `never` (default): '
+                                        'do not recompress.')
         archive_group.add_argument('--chunker-params', metavar='PARAMS', dest='chunker_params',
                                    type=ChunkerParams, default=CHUNKER_PARAMS,
                                    help='specify the chunker parameters (ALGO, CHUNK_MIN_EXP, CHUNK_MAX_EXP, '


Test patch:
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
index 55c6941b..ec88d459 100644
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -2991,6 +2991,17 @@ def test_config(self):
         self.assert_in('append_only', output)
         self.assert_in('additional_free_space', output)
         self.assert_in('id', output)
+        self.assert_not_in('last_segment_checked', output)
+
+        output = self.cmd('config', self.repository_location, 'last_segment_checked', exit_code=1)
+        self.assert_in('No option ', output)
+        self.cmd('config', self.repository_location, 'last_segment_checked', '123')
+        output = self.cmd('config', self.repository_location, 'last_segment_checked')
+        assert output == '123' + '\n'
+        output = self.cmd('config', '--list', self.repository_location)
+        self.assert_in('last_segment_checked', output)
+        self.cmd('config', '--delete', self.repository_location, 'last_segment_checked')
+
         for cfg_key, cfg_value in [
             ('additional_free_space', '2G'),
             ('repository.append_only', '1'),
@@ -3002,6 +3013,7 @@ def test_config(self):
             assert output == cfg_value + '\n'
             self.cmd('config', '--delete', self.repository_location, cfg_key)
             self.cmd('config', self.repository_location, cfg_key, exit_code=1)
+
         self.cmd('config', '--list', '--delete', self.repository_location, exit_code=2)
         self.cmd('config', self.repository_location, exit_code=2)
         self.cmd('config', self.repository_location, 'invalid-option', exit_code=1)