Browse Source

Merge pull request #679 from ThomasWaldmann/prune--list

borg prune -v --list enables the keep/prune list output, fixes #658
TW 9 years ago
parent
commit
6ff78cfb71
2 changed files with 12 additions and 6 deletions
  1. 9 3
      borg/archiver.py
  2. 3 3
      borg/testsuite/archiver.py

+ 9 - 3
borg/archiver.py

@@ -528,12 +528,15 @@ class Archiver:
         stats = Statistics()
         stats = Statistics()
         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:
             for archive in keep:
             for archive in keep:
-                logger.info('Keeping archive: %s' % format_archive(archive))
+                if args.output_list:
+                    logger.info('Keeping archive: %s' % format_archive(archive))
             for archive in to_delete:
             for archive in to_delete:
                 if args.dry_run:
                 if args.dry_run:
-                    logger.info('Would prune:     %s' % format_archive(archive))
+                    if args.output_list:
+                        logger.info('Would prune:     %s' % format_archive(archive))
                 else:
                 else:
-                    logger.info('Pruning archive: %s' % format_archive(archive))
+                    if args.output_list:
+                        logger.info('Pruning archive: %s' % format_archive(archive))
                     Archive(repository, key, manifest, archive.name, cache).delete(stats)
                     Archive(repository, key, manifest, archive.name, cache).delete(stats)
             if to_delete and not args.dry_run:
             if to_delete and not args.dry_run:
                 manifest.write()
                 manifest.write()
@@ -1184,6 +1187,9 @@ class Archiver:
         subparser.add_argument('-s', '--stats', dest='stats',
         subparser.add_argument('-s', '--stats', dest='stats',
                                action='store_true', default=False,
                                action='store_true', default=False,
                                help='print statistics for the deleted archive')
                                help='print statistics for the deleted archive')
+        subparser.add_argument('--list', dest='output_list',
+                               action='store_true', default=False,
+                               help='output verbose list of archives it keeps/prunes')
         subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN',
         subparser.add_argument('--keep-within', dest='within', type=str, metavar='WITHIN',
                                help='keep all archives within this time interval')
                                help='keep all archives within this time interval')
         subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0,
         subparser.add_argument('-H', '--keep-hourly', dest='hourly', type=int, default=0,

+ 3 - 3
borg/testsuite/archiver.py

@@ -835,7 +835,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd('init', self.repository_location)
         self.cmd('init', self.repository_location)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Would prune:     test1', output)
         self.assert_in('Would prune:     test1', output)
         output = self.cmd('list', self.repository_location)
         output = self.cmd('list', self.repository_location)
@@ -850,7 +850,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd('init', self.repository_location)
         self.cmd('init', self.repository_location)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test1', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
         self.cmd('create', self.repository_location + '::test2', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2')
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Keeping archive: test2', output)
         self.assert_in('Would prune:     test1', output)
         self.assert_in('Would prune:     test1', output)
         output = self.cmd('list', self.repository_location)
         output = self.cmd('list', self.repository_location)
@@ -867,7 +867,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd('create', self.repository_location + '::foo-2015-08-12-20:00', src_dir)
         self.cmd('create', self.repository_location + '::foo-2015-08-12-20:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-10:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-10:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-20:00', src_dir)
         self.cmd('create', self.repository_location + '::bar-2015-08-12-20:00', src_dir)
-        output = self.cmd('prune', '-v', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-')
+        output = self.cmd('prune', '-v', '--list', '--dry-run', self.repository_location, '--keep-daily=2', '--prefix=foo-')
         self.assert_in('Keeping archive: foo-2015-08-12-20:00', output)
         self.assert_in('Keeping archive: foo-2015-08-12-20:00', output)
         self.assert_in('Would prune:     foo-2015-08-12-10:00', output)
         self.assert_in('Would prune:     foo-2015-08-12-10:00', output)
         output = self.cmd('list', self.repository_location)
         output = self.cmd('list', self.repository_location)