Repository: borgbackup/borg

Issue:
Deduplicated Size shows 0 bytes with borg 1.2.0
I ran into this issue where borg info shows deduplicated size of 0 B when it should have something for this value.

If I run borg info with 1.1.17, it returns the expected value. This appears to occur for multiple archives in this particular repo. Other repos return the expected value with Borg 1.2

OLD - Borg 1.2.0

```
Archive name: 2022-03-12
Archive fingerprint: 40321bc138667a51ccb444b04a43e5f198ca887fc8aa6d0f03a4ee58056c71b0
Comment:
Hostname: hostname
Username: user
Time (start): Sat, 2022-03-12 17:42:44
Time (end): Sat, 2022-03-12 19:24:08
Duration: 1 hours 41 minutes 23.77 seconds
Number of files: 530936
Command line: /usr/local/bin/borg create --show-rc --info --progress --stats --compression auto,lz4 user@host.example.com:/mnt/backup/bluray/::2022-03-12 /array/bluray
Utilization of maximum supported archive size: 1%
------------------------------------------------------------------------------
                       Original size      Compressed size    Deduplicated size
This archive:               44.85 TB             43.48 TB                  0 B
All archives:                1.27 PB              1.23 PB             42.83 TB

                       Unique chunks         Total chunks
Chunk index:                17284323            511548486
```

OLD - Borg 1.1.17

```
Archive name: 2022-03-12
Archive fingerprint: 40321bc138667a51ccb444b04a43e5f198ca887fc8aa6d0f03a4ee58056c71b0
Comment:
Hostname: hostname
Username: user
Time (start): Sat, 2022-03-12 17:42:44
Time (end): Sat, 2022-03-12 19:24:08
Duration: 1 hours 41 minutes 23.77 seconds
Number of files: 530936
Command line: /usr/local/bin/borg create --show-rc --info --progress --stats --compression auto,lz4 user@host.example.com:/mnt/backup/bluray/::2022-03-12 /array/bluray
Utilization of maximum supported archive size: 1%
------------------------------------------------------------------------------
                       Original size      Compressed size    Deduplicated size
This archive:               44.85 TB             43.48 TB            157.25 GB
All archives:                1.28 PB              1.24 PB             42.83 TB

                       Unique chunks         Total chunks
Chunk index:                17284323            511548486
```


Discussion:
Suspicion: wrong pre12_meta cache key:

- is: fpr
- should be: (fpr, want_unique)

@Charles-Auer see PR linked above, guess that fixes it.

Update me on whether our experiment with the rebuilt cache gave a non-zero deduplicated archive size.
I deleted the pre12-meta file from the ~/.cache/borg/$repoid folder and reran the borg info /path/to/repo::archive command and it spit out the same value that I got when I used Borg 1.1.17.

```
Archive name: 2022-03-12
Archive fingerprint: 40321bc138667a51ccb444b04a43e5f198ca887fc8aa6d0f03a4ee58056c71b0
Comment:
Hostname: hostname
Username: user
Time (start): Sat, 2022-03-12 17:42:44
Time (end): Sat, 2022-03-12 19:24:08
Duration: 1 hours 41 minutes 23.77 seconds
Number of files: 530936
Command line: /usr/local/bin/borg create --show-rc --info --progress --stats --compression auto,lz4 user@host.example.com:/mnt/backup/bluray1/::2022-03-12 /array/bluray
Utilization of maximum supported archive size: 1%
------------------------------------------------------------------------------
                       Original size      Compressed size    Deduplicated size
This archive:               44.85 TB             43.48 TB            157.25 GB
All archives:                1.27 PB              1.23 PB             42.83 TB
```

If I re-ran the borg info command after it created the cache, it returned 0 bytes for the duplicated value.
Yeah, so guess my fix would work. Can you try the patch linked above?

That it first works and then not after clearing the cache is because the "all archives" code spoils the cache with wrong values.
I just pulled the latest release from your repo via: git clone --branch fix-pre12-meta-1.2 https://github.com/ThomasWaldmann/borg.git

Verified the change to archive.py and compiled it. It ran fine with the pre12-meta file removed, but if I ran it again, it behaved the same as before the patch.

Do you need any other info to see why this is still not working?
Hmm, ok, guess I need to have another look, maybe there are more bugs.

Resolving patch:
diff --git a/src/borg/archive.py b/src/borg/archive.py
--- a/src/borg/archive.py
+++ b/src/borg/archive.py
@@ -650,6 +650,12 @@ def calc_stats(self, cache, want_unique=True):
         # caching wrapper around _calc_stats which is rather slow for archives made with borg < 1.2
         have_borg12_meta = self.metadata.get('nfiles') is not None
         try:
+            if want_unique:
+                # usize is neither contained in the borg 1.2 archive metadata nor in the
+                # pre12_meta cache entry representing the same information for 1.1 archives.
+                # usize is not a static property of an archive, but must get dynamically calculated,
+                # thus we must trigger a call to self._calc_stats() to get it.
+                raise KeyError
             stats = Statistics.from_raw_dict(**cache.pre12_meta[self.fpr])
         except KeyError:  # not in pre12_meta cache
             stats = self._calc_stats(cache, want_unique=want_unique)


Test patch: