Предполагаю, что:
- вот так в Duplicity формируется время (файл dup_time.py)
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
u"""Provide time related exceptions and functions"""
from __future__ import division
from past.utils import old_div
from builtins import map
import time
import types
import re
import calendar
import sys
from duplicity import globals
from duplicity import util
# For type testing against both int and long types that works in python 2/3
if sys.version_info < (3,):
integer_types = (int, types.LongType)
else:
integer_types = (int,)
class TimeException(Exception):
pass
_interval_conv_dict = {u"s": 1, u"m": 60, u"h": 3600, u"D": 86400,
u"W": 7 * 86400, u"M": 30 * 86400, u"Y": 365 * 86400}
_integer_regexp = re.compile(u"^[0-9]+$")
_interval_regexp = re.compile(u"^([0-9]+)([smhDWMY])")
_genstr_date_regexp1 = re.compile(u"^(?P<year>[0-9]{4})[-/]"
u"(?P<month>[0-9]{1,2})[-/]"
u"(?P<day>[0-9]{1,2})$")
_genstr_date_regexp2 = re.compile(u"^(?P<month>[0-9]{1,2})[-/]"
u"(?P<day>[0-9]{1,2})[-/]"
u"(?P<year>[0-9]{4})$")
_genstr_date_regexp3 = re.compile(u"^(?P<year>[0-9]{4})"
u"(?P<month>[0-9]{2})"
u"(?P<day>[0-9]{2})Z$")
curtime = curtimestr = None
prevtime = prevtimestr = None
bad_interval_string = _(u"""Bad interval string "%s"
Intervals are specified like 2Y (2 years) or 2h30m (2.5 hours). The
allowed special characters are s, m, h, D, W, M, and Y. See the man
page for more information.""")
bad_time_string = _(u"""Bad time string "%s"
The acceptible time strings are intervals (like "3D64s"), w3-datetime
strings, like "2002-04-26T04:22:01-07:00" (strings like
"2002-04-26T04:22:01" are also acceptable - duplicity will use the
current time zone), or ordinary dates like 2/4/1997 or 2001-04-23
(various combinations are acceptable, but the month always precedes
the day).""")
def setcurtime(time_in_secs=None):
u"""Sets the current time in curtime and curtimestr"""
global curtime, curtimestr
t = time_in_secs or int(time.time())
assert type(t) in integer_types
curtime, curtimestr = t, timetostring(t)
def setprevtime(time_in_secs):
u"""Sets the previous time in prevtime and prevtimestr"""
global prevtime, prevtimestr
assert type(time_in_secs) in integer_types, prevtime
prevtime, prevtimestr = time_in_secs, timetostring(time_in_secs)
def timetostring(timeinseconds):
u"""Return w3 or duplicity datetime compliant listing of timeinseconds"""
if globals.old_filenames:
# We need to know if DST applies to append the correct offset. So
# 1. Save the tuple returned by localtime.
# 2. Pass the DST flag into gettzd
lcltime = time.localtime(timeinseconds)
return time.strftime(u"%Y-%m-%dT%H" + globals.time_separator +
u"%M" + globals.time_separator + u"%S",
lcltime) + gettzd(lcltime[-1])
else:
# DST never applies to UTC
lcltime = time.gmtime(timeinseconds)
return time.strftime(u"%Y%m%dT%H%M%SZ", lcltime)
def stringtotime(timestring):
u"""Return time in seconds from w3 or duplicity timestring
If there is an error parsing the string, or it doesn't look
like a valid datetime string, return None.
"""
try:
date, daytime = timestring[:19].split(u"T")
if len(timestring) == 16:
# new format for filename time
year, month, day = list(map(int,
[date[0:4], date[4:6], date[6:8]]))
hour, minute, second = list(map(int,
[daytime[0:2], daytime[2:4], daytime[4:6]]))
else:
# old format for filename time
year, month, day = list(map(int, date.split(u"-")))
hour, minute, second = list(map(int,
daytime.split(globals.time_separator)))
assert 1900 < year < 2100, year
assert 1 <= month <= 12
assert 1 <= day <= 31
assert 0 <= hour <= 23
assert 0 <= minute <= 59
assert 0 <= second <= 61 # leap seconds
# We want to return the time in units of seconds since the
# epoch. Unfortunately the only functin that does this
# works in terms of the current timezone and we have a
# timezone offset in the string.
timetuple = (year, month, day, hour, minute, second, -1, -1, 0)
if len(timestring) == 16:
# as said in documentation, time.gmtime() and timegm() are each others' inverse.
# As far as UTC format is used in new file format,
# do not rely on system's python DST and tzdata settings
# and use functions that working with UTC
utc_in_secs = calendar.timegm(timetuple)
else:
# mktime assumed that the tuple was a local time. Compensate
# by subtracting the value for the current timezone.
# We don't need to worry about DST here because we turned it
# off in the tuple
local_in_secs = time.mktime(timetuple)
utc_in_secs = local_in_secs - time.timezone
# Now apply the offset that we were given in the time string
# This gives the correct number of seconds from the epoch
# even when we're not in the same timezone that wrote the
# string
if len(timestring) == 16:
return int(utc_in_secs)
else:
return int(utc_in_secs + tzdtoseconds(timestring[19:]))
except (TypeError, ValueError, AssertionError):
return None
def timetopretty(timeinseconds):
u"""Return pretty version of time"""
return time.asctime(time.localtime(timeinseconds))
def stringtopretty(timestring):
u"""Return pretty version of time given w3 time string"""
return timetopretty(stringtotime(timestring))
def inttopretty(seconds):
u"""Convert num of seconds to readable string like "2 hours"."""
partlist = []
hours, seconds = divmod(seconds, 3600)
if hours > 1:
partlist.append(u"%d hours" % hours)
elif hours == 1:
partlist.append(u"1 hour")
minutes, seconds = divmod(seconds, 60)
if minutes > 1:
partlist.append(u"%d minutes" % minutes)
elif minutes == 1:
partlist.append(u"1 minute")
if seconds == 1:
partlist.append(u"1 second")
elif not partlist or seconds > 1:
if isinstance(seconds, integer_types):
partlist.append(u"%s seconds" % seconds)
else:
partlist.append(u"%.2f seconds" % seconds)
return u" ".join(partlist)
def intstringtoseconds(interval_string):
u"""Convert a string expressing an interval (e.g. "4D2s") to seconds"""
def error():
raise TimeException(bad_interval_string % util.escape(interval_string))
if len(interval_string) < 2:
error()
total = 0
while interval_string:
match = _interval_regexp.match(interval_string)
if not match:
error()
num, ext = int(match.group(1)), match.group(2)
if ext not in _interval_conv_dict or num < 0:
error()
total += num * _interval_conv_dict[ext]
interval_string = interval_string[match.end(0):]
return total
def gettzd(dstflag):
u"""Return w3's timezone identification string.
Expresed as [+/-]hh:mm. For instance, PST is -08:00. Zone is
coincides with what localtime(), etc., use.
"""
# time.daylight doesn't help us. It's a flag that indicates that we
# have a dst option for the current timezone. Compensate by allowing
# the caller to pass a flag to indicate that DST applies. This flag
# is in the same format as the last member of the tuple returned by
# time.localtime()
if dstflag > 0:
offset = old_div(-1 * time.altzone, 60)
else:
offset = old_div(-1 * time.timezone, 60)
if offset > 0:
prefix = u"+"
elif offset < 0:
prefix = u"-"
else:
return u"Z" # time is already in UTC
hours, minutes = list(map(abs, divmod(offset, 60)))
assert 0 <= hours <= 23
assert 0 <= minutes <= 59
return u"%s%02d%s%02d" % (prefix, hours, globals.time_separator, minutes)
def tzdtoseconds(tzd):
u"""Given w3 compliant TZD, return how far ahead UTC is"""
if tzd == u"Z":
return 0
assert len(tzd) == 6 # only accept forms like +08:00 for now
assert (tzd[0] == u"-" or tzd[0] == u"+") and \
tzd[3] == globals.time_separator
return -60 * (60 * int(tzd[:3]) + int(tzd[4:]))
def cmp(time1, time2):
u"""Compare time1 and time2 and return -1, 0, or 1"""
if isinstance(time1, (str, u"".__class__)):
time1 = stringtotime(time1)
assert time1 is not None
if isinstance(time2, (str, u"".__class__)):
time2 = stringtotime(time2)
assert time2 is not None
if time1 < time2:
return -1
elif time1 == time2:
return 0
else:
return 1
def genstrtotime(timestr, override_curtime=None):
u"""Convert a generic time string to a time in seconds"""
if override_curtime is None:
override_curtime = curtime
if timestr == u"now":
return override_curtime
def error():
raise TimeException(bad_time_string % util.escape(timestr))
# Test for straight integer
if _integer_regexp.search(timestr):
return int(timestr)
# Test for w3-datetime format, possibly missing tzd
# This is an ugly hack. We need to know if DST applies when doing
# gettzd. However, we don't have the flag to pass. Assume that DST
# doesn't apply and pass 0. Getting a reasonable default from
# localtime() is a bad idea, since we transition to/from DST between
# calls to this method on the same run
t = stringtotime(timestr) or stringtotime(timestr + gettzd(0))
if t:
return t
try: # test for an interval, like "2 days ago"
return override_curtime - intstringtoseconds(timestr)
except TimeException:
pass
# Now check for dates like 2001/3/23
match = (_genstr_date_regexp1.search(timestr) or
_genstr_date_regexp2.search(timestr) or
_genstr_date_regexp3.search(timestr))
if not match:
error()
timestr = u"%s-%02d-%02dT00:00:00%s" % (match.group(u'year'),
int(match.group(u'month')),
int(match.group(u'day')),
gettzd(0))
t = stringtotime(timestr)
if t:
return t
else:
error()
- а вот так формируется имя файла (файл file_namming.py)
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright 2002 Ben Escoto <ben@emerose.org>
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
u"""Produce and parse the names of duplicity's backup files"""
from builtins import str
from builtins import range
from builtins import object
import re
from duplicity import dup_time
from duplicity import globals
import sys
full_vol_re = None
full_vol_re_short = None
full_manifest_re = None
full_manifest_re_short = None
inc_vol_re = None
inc_vol_re_short = None
inc_manifest_re = None
inc_manifest_re_short = None
full_sig_re = None
full_sig_re_short = None
new_sig_re = None
new_sig_re_short = None
def prepare_regex(force=False):
global full_vol_re
global full_vol_re_short
global full_manifest_re
global full_manifest_re_short
global inc_vol_re
global inc_vol_re_short
global inc_manifest_re
global inc_manifest_re_short
global full_sig_re
global full_sig_re_short
global new_sig_re
global new_sig_re_short
# we force regex re-generation in unit tests because file prefixes might have changed
if full_vol_re and not force:
return
full_vol_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_archive + b"duplicity-full"
b"\\.(?P<time>.*?)"
b"\\.vol(?P<num>[0-9]+)"
b"\\.difftar"
b"(?P<partial>(\\.part))?"
b"($|\\.)")
full_vol_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_archive + b"df"
b"\\.(?P<time>[0-9a-z]+?)"
b"\\.(?P<num>[0-9a-z]+)"
b"\\.dt"
b"(?P<partial>(\\.p))?"
b"($|\\.)")
full_manifest_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_manifest + b"duplicity-full"
b"\\.(?P<time>.*?)"
b"\\.manifest"
b"(?P<partial>(\\.part))?"
b"($|\\.)")
full_manifest_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_manifest + b"df"
b"\\.(?P<time>[0-9a-z]+?)"
b"\\.m"
b"(?P<partial>(\\.p))?"
b"($|\\.)")
inc_vol_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_archive + b"duplicity-inc"
b"\\.(?P<start_time>.*?)"
b"\\.to\\.(?P<end_time>.*?)"
b"\\.vol(?P<num>[0-9]+)"
b"\\.difftar"
b"($|\\.)")
inc_vol_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_archive + b"di"
b"\\.(?P<start_time>[0-9a-z]+?)"
b"\\.(?P<end_time>[0-9a-z]+?)"
b"\\.(?P<num>[0-9a-z]+)"
b"\\.dt"
b"($|\\.)")
inc_manifest_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_manifest + b"duplicity-inc"
b"\\.(?P<start_time>.*?)"
b"\\.to"
b"\\.(?P<end_time>.*?)"
b"\\.manifest"
b"(?P<partial>(\\.part))?"
b"(\\.|$)")
inc_manifest_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_manifest + b"di"
b"\\.(?P<start_time>[0-9a-z]+?)"
b"\\.(?P<end_time>[0-9a-z]+?)"
b"\\.m"
b"(?P<partial>(\\.p))?"
b"(\\.|$)")
full_sig_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_signature + b"duplicity-full-signatures"
b"\\.(?P<time>.*?)"
b"\\.sigtar"
b"(?P<partial>(\\.part))?"
b"(\\.|$)")
full_sig_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_signature + b"dfs"
b"\\.(?P<time>[0-9a-z]+?)"
b"\\.st"
b"(?P<partial>(\\.p))?"
b"(\\.|$)")
new_sig_re = re.compile(b"^" + globals.file_prefix + globals.file_prefix_signature + b"duplicity-new-signatures"
b"\\.(?P<start_time>.*?)"
b"\\.to"
b"\\.(?P<end_time>.*?)"
b"\\.sigtar"
b"(?P<partial>(\\.part))?"
b"(\\.|$)")
new_sig_re_short = re.compile(b"^" + globals.file_prefix + globals.file_prefix_signature + b"dns"
b"\\.(?P<start_time>[0-9a-z]+?)"
b"\\.(?P<end_time>[0-9a-z]+?)"
b"\\.st"
b"(?P<partial>(\\.p))?"
b"(\\.|$)")
def to_base36(n):
u"""
Return string representation of n in base 36 (use 0-9 and a-z)
"""
div, mod = divmod(n, 36)
if mod <= 9:
last_digit = str(mod)
else:
last_digit = chr(ord(u'a') + mod - 10)
if sys.version_info.major >= 3:
last_digit = last_digit.encode()
if n == mod:
return last_digit
else:
return to_base36(div) + last_digit
def from_base36(s):
u"""
Convert string s in base 36 to long int
"""
total = 0
for i in range(len(s)):
total *= 36
if sys.version_info.major >= 3 and isinstance(s, bytes):
digit_ord = s[i]
else:
digit_ord = ord(s[i])
if ord(u'0') <= digit_ord <= ord(u'9'):
total += digit_ord - ord(u'0')
elif ord(u'a') <= digit_ord <= ord(u'z'):
total += digit_ord - ord(u'a') + 10
else:
assert 0, u"Digit %s in %s not in proper range" % (s[i], s)
return total
def get_suffix(encrypted, gzipped):
u"""
Return appropriate suffix depending on status of
encryption, compression, and short_filenames.
"""
if encrypted:
gzipped = False
if encrypted:
if globals.short_filenames:
suffix = b'.g'
else:
suffix = b".gpg"
elif gzipped:
if globals.short_filenames:
suffix = b".z"
else:
suffix = b'.gz'
else:
suffix = b""
return suffix
def get(type, volume_number=None, manifest=False,
encrypted=False, gzipped=False, partial=False):
u"""
Return duplicity filename of specified type
type can be "full", "inc", "full-sig", or "new-sig". volume_number
can be given with the full and inc types. If manifest is true the
filename is of a full or inc manifest file.
"""
assert dup_time.curtimestr
if encrypted:
gzipped = False
suffix = get_suffix(encrypted, gzipped)
part_string = b""
if globals.short_filenames:
if partial:
part_string = b".p"
else:
if partial:
part_string = b".part"
if type == u"full-sig" or type == u"new-sig":
assert not volume_number and not manifest
assert not (volume_number and part_string)
if type == u"full-sig":
if globals.short_filenames:
return (globals.file_prefix + globals.file_prefix_signature +
b"dfs.%s.st%s%s" %
(to_base36(dup_time.curtime), part_string, suffix))
else:
return (globals.file_prefix + globals.file_prefix_signature +
b"duplicity-full-signatures.%s.sigtar%s%s" %
(dup_time.curtimestr.encode(), part_string, suffix))
elif type == u"new-sig":
if globals.short_filenames:
return (globals.file_prefix + globals.file_prefix_signature +
b"dns.%s.%s.st%s%s" %
(to_base36(dup_time.prevtime),
to_base36(dup_time.curtime),
part_string, suffix))
else:
return (globals.file_prefix + globals.file_prefix_signature +
b"duplicity-new-signatures.%s.to.%s.sigtar%s%s" %
(dup_time.prevtimestr.encode(), dup_time.curtimestr.encode(),
part_string, suffix))
else:
assert volume_number or manifest
assert not (volume_number and manifest)
prefix = globals.file_prefix
if volume_number:
if globals.short_filenames:
vol_string = b"%s.dt" % to_base36(volume_number)
else:
vol_string = b"vol%d.difftar" % volume_number
prefix += globals.file_prefix_archive
else:
if globals.short_filenames:
vol_string = b"m"
else:
vol_string = b"manifest"
prefix += globals.file_prefix_manifest
if type == u"full":
if globals.short_filenames:
return (b"%sdf.%s.%s%s%s" % (prefix, to_base36(dup_time.curtime),
vol_string, part_string, suffix))
else:
return (b"%sduplicity-full.%s.%s%s%s" % (prefix, dup_time.curtimestr.encode(),
vol_string, part_string, suffix))
elif type == u"inc":
if globals.short_filenames:
return (b"%sdi.%s.%s.%s%s%s" % (prefix, to_base36(dup_time.prevtime),
to_base36(dup_time.curtime),
vol_string, part_string, suffix))
else:
return (b"%sduplicity-inc.%s.to.%s.%s%s%s" % (prefix, dup_time.prevtimestr.encode(),
dup_time.curtimestr.encode(),
vol_string, part_string, suffix))
else:
assert 0
def parse(filename):
u"""
Parse duplicity filename, return None or ParseResults object
"""
def str2time(timestr, short):
u"""
Return time in seconds if string can be converted, None otherwise
"""
if isinstance(timestr, bytes):
timestr = timestr.decode()
if short:
t = from_base36(timestr)
else:
try:
t = dup_time.genstrtotime(timestr.upper())
except dup_time.TimeException:
return None
return t
def get_vol_num(s, short):
u"""
Return volume number from volume number string
"""
if short:
return from_base36(s)
else:
return int(s)
def check_full():
u"""
Return ParseResults if file is from full backup, None otherwise
"""
prepare_regex()
short = True
m1 = full_vol_re_short.search(filename)
m2 = full_manifest_re_short.search(filename)
if not m1 and not m2 and not globals.short_filenames:
short = False
m1 = full_vol_re.search(filename)
m2 = full_manifest_re.search(filename)
if m1 or m2:
t = str2time((m1 or m2).group(u"time"), short)
if t:
if m1:
return ParseResults(u"full", time=t,
volume_number=get_vol_num(m1.group(u"num"), short))
else:
return ParseResults(u"full", time=t, manifest=True,
partial=(m2.group(u"partial") is not None))
return None
def check_inc():
u"""
Return ParseResults if file is from inc backup, None otherwise
"""
prepare_regex()
short = True
m1 = inc_vol_re_short.search(filename)
m2 = inc_manifest_re_short.search(filename)
if not m1 and not m2 and not globals.short_filenames:
short = False
m1 = inc_vol_re.search(filename)
m2 = inc_manifest_re.search(filename)
if m1 or m2:
t1 = str2time((m1 or m2).group(u"start_time"), short)
t2 = str2time((m1 or m2).group(u"end_time"), short)
if t1 and t2:
if m1:
return ParseResults(u"inc", start_time=t1,
end_time=t2, volume_number=get_vol_num(m1.group(u"num"), short))
else:
return ParseResults(u"inc", start_time=t1, end_time=t2, manifest=1,
partial=(m2.group(u"partial") is not None))
return None
def check_sig():
u"""
Return ParseResults if file is a signature, None otherwise
"""
prepare_regex()
short = True
m = full_sig_re_short.search(filename)
if not m and not globals.short_filenames:
short = False
m = full_sig_re.search(filename)
if m:
t = str2time(m.group(u"time"), short)
if t:
return ParseResults(u"full-sig", time=t,
partial=(m.group(u"partial") is not None))
else:
return None
short = True
m = new_sig_re_short.search(filename)
if not m and not globals.short_filenames:
short = False
m = new_sig_re.search(filename)
if m:
t1 = str2time(m.group(u"start_time"), short)
t2 = str2time(m.group(u"end_time"), short)
if t1 and t2:
return ParseResults(u"new-sig", start_time=t1, end_time=t2,
partial=(m.group(u"partial") is not None))
return None
def set_encryption_or_compression(pr):
u"""
Set encryption and compression flags in ParseResults pr
"""
if (filename.endswith(b'.z') or
not globals.short_filenames and filename.endswith(b'gz')):
pr.compressed = 1
else:
pr.compressed = None
if (filename.endswith(b'.g') or
not globals.short_filenames and filename.endswith(b'.gpg')):
pr.encrypted = 1
else:
pr.encrypted = None
pr = check_full()
if not pr:
pr = check_inc()
if not pr:
pr = check_sig()
if not pr:
return None
set_encryption_or_compression(pr)
return pr
class ParseResults(object):
u"""
Hold information taken from a duplicity filename
"""
def __init__(self, type, manifest=None, volume_number=None,
time=None, start_time=None, end_time=None,
encrypted=None, compressed=None, partial=False):
assert type in [u"full-sig", u"new-sig", u"inc", u"full"]
self.type = type
if type == u"inc" or type == u"full":
assert manifest or volume_number
if type == u"inc" or type == u"new-sig":
assert start_time and end_time
else:
assert time
self.manifest = manifest
self.volume_number = volume_number
self.time = time
self.start_time, self.end_time = start_time, end_time
self.compressed = compressed # true if gzip compressed
self.encrypted = encrypted # true if gpg encrypted
self.partial = partial
def __eq__(self, other):
return self.type == other.type and \
self.manifest == other.manifest and \
self.time == other.time and \
self.start_time == other.start_time and \
self.end_time == other.end_time and \
self.partial == other.partial
После множества экспериментов, общая картина не меняется. Время в названии файлов "отстает" на 3 часа. Сейчас RTC time и Local time совпадают, NTP service отключен.
Варианты:
- Большое количество экспериментов "что-то" сломали, все нужно ставить на "чистую", т.к. отмотать все действия назад будет затруднительно (не документировались)
- Какие-нибудь еще идеи, ранее не проверенные )))
Пользователь добавил сообщение 04 Июня 2022, 06:08:26:
Буду признателен за любые идеи. Система тестовая, эксперименты приветствуются.