mirror of https://github.com/borgbackup/borg.git
fix wrong duration if clock jumps during create
This commit is contained in:
parent
4f0c2ab68c
commit
420c984f05
|
@ -1,5 +1,5 @@
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
import errno
|
import errno
|
||||||
|
@ -186,7 +186,7 @@ class Archive:
|
||||||
|
|
||||||
def __init__(self, repository, key, manifest, name, cache=None, create=False,
|
def __init__(self, repository, key, manifest, name, cache=None, create=False,
|
||||||
checkpoint_interval=300, numeric_owner=False, noatime=False, noctime=False, progress=False,
|
checkpoint_interval=300, numeric_owner=False, noatime=False, noctime=False, progress=False,
|
||||||
chunker_params=CHUNKER_PARAMS, start=None, end=None):
|
chunker_params=CHUNKER_PARAMS, start=None, start_monotonic=None, end=None):
|
||||||
self.cwd = os.getcwd()
|
self.cwd = os.getcwd()
|
||||||
self.key = key
|
self.key = key
|
||||||
self.repository = repository
|
self.repository = repository
|
||||||
|
@ -200,9 +200,12 @@ class Archive:
|
||||||
self.numeric_owner = numeric_owner
|
self.numeric_owner = numeric_owner
|
||||||
self.noatime = noatime
|
self.noatime = noatime
|
||||||
self.noctime = noctime
|
self.noctime = noctime
|
||||||
|
assert (start is None) == (start_monotonic is None), 'Logic error: if start is given, start_monotonic must be given as well and vice versa.'
|
||||||
if start is None:
|
if start is None:
|
||||||
start = datetime.utcnow()
|
start = datetime.utcnow()
|
||||||
|
start_monotonic = time.monotonic()
|
||||||
self.start = start
|
self.start = start
|
||||||
|
self.start_monotonic = start_monotonic
|
||||||
if end is None:
|
if end is None:
|
||||||
end = datetime.utcnow()
|
end = datetime.utcnow()
|
||||||
self.end = end
|
self.end = end
|
||||||
|
@ -302,7 +305,7 @@ Number of files: {0.stats.nfiles}'''.format(
|
||||||
raise self.AlreadyExists(name)
|
raise self.AlreadyExists(name)
|
||||||
self.items_buffer.flush(flush=True)
|
self.items_buffer.flush(flush=True)
|
||||||
if timestamp is None:
|
if timestamp is None:
|
||||||
self.end = datetime.utcnow()
|
self.end = self.start + timedelta(seconds=time.monotonic() - self.start_monotonic)
|
||||||
start = self.start
|
start = self.start
|
||||||
end = self.end
|
end = self.end
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -5,7 +5,6 @@ from operator import attrgetter
|
||||||
import argparse
|
import argparse
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
|
@ -13,6 +12,7 @@ import signal
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
|
@ -263,7 +263,6 @@ class Archiver:
|
||||||
if args.progress:
|
if args.progress:
|
||||||
archive.stats.show_progress(final=True)
|
archive.stats.show_progress(final=True)
|
||||||
if args.stats:
|
if args.stats:
|
||||||
archive.end = datetime.utcnow()
|
|
||||||
log_multi(DASHES,
|
log_multi(DASHES,
|
||||||
str(archive),
|
str(archive),
|
||||||
DASHES,
|
DASHES,
|
||||||
|
@ -276,6 +275,7 @@ class Archiver:
|
||||||
self.ignore_inode = args.ignore_inode
|
self.ignore_inode = args.ignore_inode
|
||||||
dry_run = args.dry_run
|
dry_run = args.dry_run
|
||||||
t0 = datetime.utcnow()
|
t0 = datetime.utcnow()
|
||||||
|
t0_monotonic = time.monotonic()
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
key.compressor = Compressor(**args.compression)
|
key.compressor = Compressor(**args.compression)
|
||||||
with Cache(repository, key, manifest, do_files=args.cache_files, lock_wait=self.lock_wait) as cache:
|
with Cache(repository, key, manifest, do_files=args.cache_files, lock_wait=self.lock_wait) as cache:
|
||||||
|
@ -283,7 +283,7 @@ class Archiver:
|
||||||
create=True, checkpoint_interval=args.checkpoint_interval,
|
create=True, checkpoint_interval=args.checkpoint_interval,
|
||||||
numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
|
numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
|
||||||
progress=args.progress,
|
progress=args.progress,
|
||||||
chunker_params=args.chunker_params, start=t0)
|
chunker_params=args.chunker_params, start=t0, start_monotonic=t0_monotonic)
|
||||||
create_inner(archive, cache)
|
create_inner(archive, cache)
|
||||||
else:
|
else:
|
||||||
create_inner(None, None)
|
create_inner(None, None)
|
||||||
|
|
Loading…
Reference in New Issue