Răsfoiți Sursa

borg compact --cleanup-commits to get rid of leftover 17byte segments

see #2850.
Thomas Waldmann 7 ani în urmă
părinte
comite
755eaeec0a
3 a modificat fișierele cu 14 adăugiri și 4 ștergeri
  1. 3 1
      src/borg/archiver.py
  2. 3 2
      src/borg/remote.py
  3. 8 1
      src/borg/repository.py

+ 3 - 1
src/borg/archiver.py

@@ -1540,7 +1540,7 @@ class Archiver:
         # see the comment in do_with_lock about why we do it like this:
         data = repository.get(Manifest.MANIFEST_ID)
         repository.put(Manifest.MANIFEST_ID, data)
-        repository.commit(compact=True)
+        repository.commit(compact=True, cleanup_commits=args.cleanup_commits)
         return EXIT_SUCCESS
 
     @with_repository(exclusive=True, manifest=False)
@@ -3707,6 +3707,8 @@ class Archiver:
         subparser.add_argument('location', metavar='REPOSITORY',
                                type=location_validator(archive=False),
                                help='repository to compact')
+        subparser.add_argument('--cleanup-commits', dest='cleanup_commits', action='store_true',
+                               help='cleanup commit-only 17-byte segment files')
 
         config_epilog = process_epilog("""
         This command gets and sets options in a local repository or cache config file.

+ 3 - 2
src/borg/remote.py

@@ -890,8 +890,9 @@ This problem will go away as soon as the server has been upgraded to 1.0.7+.
         """actual remoting is done via self.call in the @api decorator"""
 
     @api(since=parse_version('1.0.0'),
-         compact={'since': parse_version('1.2.0a0'), 'previously': True})
-    def commit(self, save_space=False, compact=True):
+         compact={'since': parse_version('1.2.0a0'), 'previously': True},
+         cleanup_commits={'since': parse_version('1.2.0a0'), 'previously': False})
+    def commit(self, save_space=False, compact=True, cleanup_commits=False):
         """actual remoting is done via self.call in the @api decorator"""
 
     @api(since=parse_version('1.0.0'))

+ 8 - 1
src/borg/repository.py

@@ -416,7 +416,7 @@ class Repository:
             self.lock.release()
             self.lock = None
 
-    def commit(self, save_space=False, compact=True):
+    def commit(self, save_space=False, compact=True, cleanup_commits=False):
         """Commit transaction
         """
         # save_space is not used anymore, but stays for RPC/API compatibility.
@@ -430,6 +430,13 @@ class Repository:
         self.segments.setdefault(segment, 0)
         self.compact[segment] += LoggedIO.header_fmt.size
         if compact and not self.append_only:
+            if cleanup_commits:
+                # due to bug #2850, there might be a lot of commit-only segment files.
+                # this is for a one-time cleanup of these 17byte files.
+                for segment, filename in self.io.segment_iterator():
+                    if os.path.getsize(filename) == 17:
+                        self.segments[segment] = 0
+                        self.compact[segment] = LoggedIO.header_fmt.size
             self.compact_segments()
         self.write_index()
         self.rollback()