mirror of https://github.com/borgbackup/borg.git
Borg recreate timestamp is a no op (#4815)
recreate: support --timestamp option, fixes #4745
This commit is contained in:
parent
e393dd4fe1
commit
a029d686b5
|
@ -1852,7 +1852,7 @@ class ArchiveRecreater:
|
|||
exclude_caches=False, exclude_if_present=None, keep_exclude_tags=False,
|
||||
chunker_params=None, compression=None, recompress=False, always_recompress=False,
|
||||
dry_run=False, stats=False, progress=False, file_status_printer=None,
|
||||
checkpoint_interval=1800):
|
||||
timestamp=None, checkpoint_interval=1800):
|
||||
self.repository = repository
|
||||
self.key = key
|
||||
self.manifest = manifest
|
||||
|
@ -1872,6 +1872,7 @@ class ArchiveRecreater:
|
|||
self.compression = compression or CompressionSpec('none')
|
||||
self.seen_chunks = set()
|
||||
|
||||
self.timestamp = timestamp
|
||||
self.dry_run = dry_run
|
||||
self.stats = stats
|
||||
self.progress = progress
|
||||
|
@ -1976,18 +1977,33 @@ class ArchiveRecreater:
|
|||
return
|
||||
if comment is None:
|
||||
comment = archive.metadata.get('comment', '')
|
||||
target.save(comment=comment, stats=target.stats, additional_metadata={
|
||||
# keep some metadata as in original archive:
|
||||
'time': archive.metadata.time,
|
||||
'time_end': archive.metadata.get('time_end') or archive.metadata.time,
|
||||
'cmdline': archive.metadata.cmdline,
|
||||
# but also remember recreate metadata:
|
||||
'recreate_cmdline': sys.argv,
|
||||
})
|
||||
|
||||
# Keep for the statistics if necessary
|
||||
if self.stats:
|
||||
_start = target.start
|
||||
|
||||
if self.timestamp is None:
|
||||
additional_metadata = {
|
||||
'time': archive.metadata.time,
|
||||
'time_end': archive.metadata.get('time_end') or archive.metadata.time,
|
||||
'cmdline': archive.metadata.cmdline,
|
||||
# but also remember recreate metadata:
|
||||
'recreate_cmdline': sys.argv,
|
||||
}
|
||||
else:
|
||||
additional_metadata = {
|
||||
'cmdline': archive.metadata.cmdline,
|
||||
# but also remember recreate metadata:
|
||||
'recreate_cmdline': sys.argv,
|
||||
}
|
||||
|
||||
target.save(comment=comment, timestamp=self.timestamp,
|
||||
stats=target.stats, additional_metadata=additional_metadata)
|
||||
if replace_original:
|
||||
archive.delete(Statistics(), progress=self.progress)
|
||||
target.rename(archive.name)
|
||||
if self.stats:
|
||||
target.start = _start
|
||||
target.end = datetime.utcnow()
|
||||
log_multi(DASHES,
|
||||
str(target),
|
||||
|
|
|
@ -1560,7 +1560,7 @@ class Archiver:
|
|||
progress=args.progress, stats=args.stats,
|
||||
file_status_printer=self.print_file_status,
|
||||
checkpoint_interval=args.checkpoint_interval,
|
||||
dry_run=args.dry_run)
|
||||
dry_run=args.dry_run, timestamp=args.timestamp)
|
||||
|
||||
if args.location.archive:
|
||||
name = args.location.archive
|
||||
|
|
|
@ -2551,6 +2551,17 @@ class ArchiverTestCase(ArchiverTestCaseBase):
|
|||
assert int(csize) < int(size)
|
||||
assert sha256_before == sha256_after
|
||||
|
||||
def test_recreate_timestamp(self):
|
||||
self.create_test_files()
|
||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||
archive = self.repository_location + '::test0'
|
||||
self.cmd('create', archive, 'input')
|
||||
self.cmd('recreate', '--timestamp', "1970-01-02T00:00:00", '--comment',
|
||||
'test', archive)
|
||||
info = self.cmd('info', archive).splitlines()
|
||||
assert any([re.search(r'Time \(start\).+ 1970-01-02', item) for item in info])
|
||||
assert any([re.search(r'Time \(end\).+ 1970-01-02', item) for item in info])
|
||||
|
||||
def test_recreate_dry_run(self):
|
||||
self.create_regular_file('compressible', size=10000)
|
||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||
|
|
Loading…
Reference in New Issue