implement noatime / noctime, fixes #1853

This commit is contained in:
Thomas Waldmann 2016-11-26 21:12:16 +01:00
parent 20798df7e3
commit 9451ab6534
2 changed files with 18 additions and 4 deletions

View File

@ -185,7 +185,7 @@ class Archive:
"""Failed to encode filename "{}" into file system encoding "{}". Consider configuring the LANG environment variable."""
def __init__(self, repository, key, manifest, name, cache=None, create=False,
checkpoint_interval=300, numeric_owner=False, progress=False,
checkpoint_interval=300, numeric_owner=False, noatime=False, noctime=False, progress=False,
chunker_params=CHUNKER_PARAMS, start=None, end=None):
self.cwd = os.getcwd()
self.key = key
@ -198,6 +198,8 @@ class Archive:
self.name = name
self.checkpoint_interval = checkpoint_interval
self.numeric_owner = numeric_owner
self.noatime = noatime
self.noctime = noctime
if start is None:
start = datetime.utcnow()
self.start = start
@ -571,10 +573,15 @@ Number of files: {0.stats.nfiles}'''.format(
b'mode': st.st_mode,
b'uid': st.st_uid, b'user': uid2user(st.st_uid),
b'gid': st.st_gid, b'group': gid2group(st.st_gid),
b'atime': int_to_bigint(st.st_atime_ns),
b'ctime': int_to_bigint(st.st_ctime_ns),
b'mtime': int_to_bigint(st.st_mtime_ns),
}
# borg can work with archives only having mtime (older attic archives do not have
# atime/ctime). it can be useful to omit atime/ctime, if they change without the
# file content changing - e.g. to get better metadata deduplication.
if not self.noatime:
item[b'atime'] = int_to_bigint(st.st_atime_ns)
if not self.noctime:
item[b'ctime'] = int_to_bigint(st.st_ctime_ns)
if self.numeric_owner:
item[b'user'] = item[b'group'] = None
with backup_io():

View File

@ -281,7 +281,8 @@ class Archiver:
with Cache(repository, key, manifest, do_files=args.cache_files, lock_wait=self.lock_wait) as cache:
archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
create=True, checkpoint_interval=args.checkpoint_interval,
numeric_owner=args.numeric_owner, progress=args.progress,
numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
progress=args.progress,
chunker_params=args.chunker_params, start=t0)
create_inner(archive, cache)
else:
@ -1301,6 +1302,12 @@ class Archiver:
subparser.add_argument('--numeric-owner', dest='numeric_owner',
action='store_true', default=False,
help='only store numeric user and group identifiers')
subparser.add_argument('--noatime', dest='noatime',
action='store_true', default=False,
help='do not store atime into archive')
subparser.add_argument('--noctime', dest='noctime',
action='store_true', default=False,
help='do not store ctime into archive')
subparser.add_argument('--timestamp', dest='timestamp',
type=timestamp, default=None,
metavar='yyyy-mm-ddThh:mm:ss',