Repository: borgbackup/borg

Issue:
recreate mixes original and recreated start/end time
```
Time (start): Mon, 2017-04-03 21:27:35
Time (end):   Tue, 2017-04-04 18:36:10
Duration: 21 hours 8 minutes 34.32 seconds
```


Discussion:
it's not quite clear from the posted output what precisely the bug is.
```
(borg-env)tw@tux:~/w/borg$ borg init -e none repo

(borg-env)tw@tux:~/w/borg$ borg create repo::2 .
(borg-env)tw@tux:~/w/borg$ borg info repo::2
Archive name: 2
Archive fingerprint: 6523505b3b85885ff492442cf928e04df01cd2ff78ca86616d80581bb6b30f77
Comment: 
Hostname: tux
Username: tw
Time (start): Sat, 2017-06-03 15:28:28
Time (end): Sat, 2017-06-03 15:28:45
Duration: 16.59 seconds
Number of files: 17047
Command line: /home/tw/w/borg-env/bin/borg create repo::2 .
...

(borg-env)tw@tux:~/w/borg$ borg recreate repo::2 --target 3 --compress none --recompress always
recreate is an experimental feature.
Type 'YES' if you understand this and want to continue: YES
(borg-env)tw@tux:~/w/borg$ borg info repo::3
Archive name: 3
Archive fingerprint: 86ad70485bab8d10bd5027ca3e709370b5561f2170475e62f65f14278babc9b1
Comment: 
Hostname: tux
Username: tw
Time (start): Sat, 2017-06-03 15:28:19
Time (end): Sat, 2017-06-03 15:28:28
Duration: 8.87 seconds
Number of files: 17047
Command line: /home/tw/w/borg-env/bin/borg create repo::2 .
...
```
Note (unrelated to this bug): before finding working recreate options, I did this:
```
(borg-env)tw@tux:~/w/borg$ borg recreate repo::2 --target 3
recreate is an experimental feature.
Type 'YES' if you understand this and want to continue: YES
(borg-env)tw@tux:~/w/borg$ borg info repo::3
Archive 3 does not exist

(borg-env)tw@tux:~/w/borg$ borg recreate repo::2 --target 3 --compress none
recreate is an experimental feature.
Type 'YES' if you understand this and want to continue: YES
(borg-env)tw@tux:~/w/borg$ borg info repo::3
Archive 3 does not exist
```
Strange: it does nothing, but does not give warning/error output.
So, the timestamp issue is this:

original archive:
```
Time (start): Sat, 2017-06-03 15:28:28
Time (end): Sat, 2017-06-03 15:28:45
Duration: 16.59 seconds
```
recreated archive:
```
Time (start): Sat, 2017-06-03 15:28:19
Time (end): Sat, 2017-06-03 15:28:28
Duration: 8.87 seconds
```
Seems to have changed (perhaps due to the changed start/end calculation since 1.0.10 or so).
So, what is the desired state for the recreated timestamps?
- keep original timestamps and duration (preserve information about when original backup happened and how long it took)
- update timestamps with data from recreate run (start, end, duration) and lose original timestamp

Also to consider: we keep the original commandline which might be misleading considering the potentially altered state / contents of the recreated archive. How about using "orig_cmd ; recreate_cmd"?
The recreate commandline is already stored. Just not shown in info.
Considering that there could be multiple recreates on an archive, using a log for original command + all subsequent commands comes to mind, like:

2017-06-01 23:59:00 original create command
2017-06-02 23:42:00 recreate command
2017-06-03 01:02:03 another recreate command

And abandon the (only single) recreate command we store now?

Resolving patch:
diff --git a/src/borg/archive.py b/src/borg/archive.py
--- a/src/borg/archive.py
+++ b/src/borg/archive.py
@@ -1699,11 +1699,14 @@ def iter_chunks(self, archive, target, chunks):
     def save(self, archive, target, comment=None, replace_original=True):
         if self.dry_run:
             return
-        timestamp = archive.ts.replace(tzinfo=None)
         if comment is None:
             comment = archive.metadata.get('comment', '')
-        target.save(timestamp=timestamp, comment=comment, additional_metadata={
+        target.save(comment=comment, additional_metadata={
+            # keep some metadata as in original archive:
+            'time': archive.metadata.time,
+            'time_end': archive.metadata.time_end,
             'cmdline': archive.metadata.cmdline,
+            # but also remember recreate metadata:
             'recreate_cmdline': sys.argv,
         })
         if replace_original:


Test patch: