浏览代码

implement noatime / noctime, fixes #1853

Thomas Waldmann 8 年之前
父节点
当前提交
9451ab6534
共有 2 个文件被更改,包括 18 次插入4 次删除
  1. 10 3
      borg/archive.py
  2. 8 1
      borg/archiver.py

+ 10 - 3
borg/archive.py

@@ -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():

+ 8 - 1
borg/archiver.py

@@ -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',