From a078d730e1c77e0498b70379441c537528f6afc1 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 5 Feb 2016 00:18:24 +0100 Subject: [PATCH 1/3] archive creation start/end timestamp: use utc the timestamp given via cli is already expected to be utc. the timestamp which is automatically created when no cli timestamp is given is also utc. thus, also use utc for .start and .end. --- borg/archive.py | 2 +- borg/archiver.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index ab7ff199e..0b977b561 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -128,7 +128,7 @@ class Archive: def __init__(self, repository, key, manifest, name, cache=None, create=False, checkpoint_interval=300, numeric_owner=False, progress=False, chunker_params=CHUNKER_PARAMS, - start=datetime.now(), end=datetime.now()): + start=datetime.utcnow(), end=datetime.utcnow()): self.cwd = os.getcwd() self.key = key self.repository = repository diff --git a/borg/archiver.py b/borg/archiver.py index 115b2bc38..664bd0df1 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -191,7 +191,7 @@ class Archiver: if args.progress: archive.stats.show_progress(final=True) if args.stats: - archive.end = datetime.now() + archive.end = datetime.utcnow() log_multi(DASHES, str(archive), DASHES, @@ -202,7 +202,7 @@ class Archiver: self.output_filter = args.output_filter self.output_list = args.output_list dry_run = args.dry_run - t0 = datetime.now() + t0 = datetime.utcnow() if not dry_run: repository = self.open_repository(args, exclusive=True) manifest, key = Manifest.load(repository) From 38d2237dadbfd36eef08c4869ff18bc3485ac622 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 5 Feb 2016 00:23:54 +0100 Subject: [PATCH 2/3] archive metadata: store backup START time into 'time' except if a timestamp is given via cli, then store that time into 'time' --- borg/archive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borg/archive.py b/borg/archive.py index 0b977b561..f636d1671 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -226,7 +226,7 @@ Number of files: {0.stats.nfiles}'''.format(self) raise self.AlreadyExists(name) self.items_buffer.flush(flush=True) if timestamp is None: - timestamp = datetime.utcnow() + timestamp = self.start metadata = StableDict({ 'version': 1, 'name': name, From a9f523e5ce8b46dc05601fc17479f362b3d1f8b4 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 5 Feb 2016 02:02:04 +0100 Subject: [PATCH 3/3] archive metadata: store backup END time into 'time_end', display it in "borg info", fixes #627 ... except if a timestamp is given via cli, then store that time into 'time_end' --- borg/archive.py | 20 +++++++++++++++----- borg/archiver.py | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index f636d1671..aaa907b34 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -172,15 +172,20 @@ class Archive: def load(self, id): self.id = id self.metadata = self._load_meta(self.id) - decode_dict(self.metadata, (b'name', b'hostname', b'username', b'time')) + decode_dict(self.metadata, (b'name', b'hostname', b'username', b'time', b'time_end')) self.metadata[b'cmdline'] = [arg.decode('utf-8', 'surrogateescape') for arg in self.metadata[b'cmdline']] self.name = self.metadata[b'name'] @property def ts(self): - """Timestamp of archive creation in UTC""" + """Timestamp of archive creation (start) in UTC""" return parse_timestamp(self.metadata[b'time']) + @property + def ts_end(self): + """Timestamp of archive creation (end) in UTC""" + return parse_timestamp(self.metadata[b'time_end']) + @property def fpr(self): return hexlify(self.id).decode('ascii') @@ -226,7 +231,11 @@ Number of files: {0.stats.nfiles}'''.format(self) raise self.AlreadyExists(name) self.items_buffer.flush(flush=True) if timestamp is None: - timestamp = self.start + start = self.start + end = self.end + else: + start = timestamp + end = timestamp # we only have 1 value metadata = StableDict({ 'version': 1, 'name': name, @@ -234,7 +243,8 @@ Number of files: {0.stats.nfiles}'''.format(self) 'cmdline': sys.argv, 'hostname': socket.gethostname(), 'username': getuser(), - 'time': timestamp.isoformat(), + 'time': start.isoformat(), + 'time_end': end.isoformat(), }) data = msgpack.packb(metadata, unicode_errors='surrogateescape') self.id = self.key.id_hash(data) @@ -851,7 +861,7 @@ class ArchiveChecker: archive = StableDict(msgpack.unpackb(data)) if archive[b'version'] != 1: raise Exception('Unknown archive metadata version') - decode_dict(archive, (b'name', b'hostname', b'username', b'time')) + decode_dict(archive, (b'name', b'hostname', b'username', b'time', b'time_end')) archive[b'cmdline'] = [arg.decode('utf-8', 'surrogateescape') for arg in archive[b'cmdline']] items_buffer = ChunkBuffer(self.key) items_buffer.write_chunk = add_callback diff --git a/borg/archiver.py b/borg/archiver.py index 664bd0df1..242de2de4 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -489,7 +489,8 @@ class Archiver: print('Fingerprint: %s' % hexlify(archive.id).decode('ascii')) print('Hostname:', archive.metadata[b'hostname']) print('Username:', archive.metadata[b'username']) - print('Time: %s' % format_time(to_localtime(archive.ts))) + print('Time (start): %s' % format_time(to_localtime(archive.ts))) + print('Time (end): %s' % format_time(to_localtime(archive.ts_end))) print('Command line:', remove_surrogates(' '.join(archive.metadata[b'cmdline']))) print('Number of files: %d' % stats.nfiles) print()