Skip to content

Archives filters - #1554

Merged
ThomasWaldmann merged 7 commits into
borgbackup:masterfrom
funkyfuture:archives_filters
Sep 30, 2016
Merged

Archives filters#1554
ThomasWaldmann merged 7 commits into
borgbackup:masterfrom
funkyfuture:archives_filters

Conversation

@funkyfuture

@funkyfuture funkyfuture commented Aug 30, 2016

Copy link
Copy Markdown
Contributor

follow-up of #1369

this adds the arguments --first, --last and --sort-by, and groups them with --prefix as archives filters that can be applied on repository targets.

usable with check, delete, info and list.

use-case in a script:

while used_space_exceeds_pcent; do
    log 'Used space exceeds ${MAX_DISK_USAGE}%, deleting oldest backup archive.'
    borg delete --first 1 --force $BORG_REPOSITORY & wait
done

@funkyfuture

Copy link
Copy Markdown
Contributor Author

strange, locally 42cd980 appears as second of these commits.

@codecov-io

codecov-io commented Aug 30, 2016

Copy link
Copy Markdown

Current coverage is 84.68% (diff: 84.74%)

Merging #1554 into master will decrease coverage by 0.07%

@@             master      #1554   diff @@
==========================================
  Files            20         20          
  Lines          6481       6548    +67   
  Methods           0          0          
  Messages          0          0          
  Branches       1093       1112    +19   
==========================================
+ Hits           5493       5545    +52   
- Misses          727        735     +8   
- Partials        261        268     +7   

Powered by Codecov. Last update f276e30...089995e

Comment thread src/borg/archiver.py Outdated
group.add_argument('--first', dest='first', metavar='N', default=0, type=int,
help='delete N first archives')
group.add_argument('--last', dest='last', metavar='N', default=0, type=int,
help='delete N last archives')

@ThomasWaldmann ThomasWaldmann Aug 30, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it always says "delete", no matter to where you add these filter args.
so, how about "consider N first/last archives".
please create a fixup commit just for this.

@funkyfuture

Copy link
Copy Markdown
Contributor Author

ai'ght, thanks for the feedback. i changed the commits where the solution was clear to me.

Comment thread src/borg/archiver.py Outdated
group.add_argument('--first', dest='first', metavar='N', default=0, type=int,
help='select first N archives')
group.add_argument('--last', dest='last', metavar='N', default=0, type=int,
help='delete last N archives')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you call this method from list, delete, check, ... right?
so the help texts are still wrong.
i suggested the wording "consider first/last N archives" in a previous review.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. i made it a little more explicit now: consider last N archives after other filter args were applied. that okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@funkyfuture

Copy link
Copy Markdown
Contributor Author

okay, i did a fix commit concerning the remaining issues. to rebase it is kind of a pita.

@ThomasWaldmann

Copy link
Copy Markdown
Member

any idea how to review d61c778 ?

@funkyfuture

Copy link
Copy Markdown
Contributor Author

maybe with two screens, reading both revisions side-by-side rather than with a diff view

@ThomasWaldmann

Copy link
Copy Markdown
Member

Sorry, I can't review d61c778 .

It somehow looks better than the old code, but I can not see whether it still does the same thing and works correctly (except what is covered by the still succeeding unit tests). At the same time, this is critical code with the capability to either not repair your repo or make stuff even worse, if things go wrong.

So, anybody else wants to review this?

Or, remove it from this PR to get the rest adopted more quickly?

In general, I would advise doing less complex/big changesets and especially hold back from refactoring / cleaning up and introducing new features within the same changeset (or even PR) - it just messes up the limited diff view on github and makes things hard to review.

@funkyfuture

Copy link
Copy Markdown
Contributor Author

since you changed the ArchiveChecker and i was really not keen to rebase onto that, i removed the commit in question.

concerning the review, i have no other idea than (more?!) tests and reading.

@enkore

enkore commented Sep 30, 2016

Copy link
Copy Markdown
Contributor

Can you rebase this on current master? Thanks!

Comment thread src/borg/archiver.py Outdated

group = filters_group.add_mutually_exclusive_group()
group.add_argument('--first', dest='first', metavar='N', default=0, type=int,
help='consider first N archives after other filter args were applied')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: "after other filters were applied"

Comment thread src/borg/archiver.py Outdated
group.add_argument('--first', dest='first', metavar='N', default=0, type=int,
help='consider first N archives after other filter args were applied')
group.add_argument('--last', dest='last', metavar='N', default=0, type=int,
help='consider last N archives after other filter args were applied')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment thread src/borg/helpers.py
def list(self, sort_by=None, reverse=False, prefix=''):
""" Inexpensive Archive.list_archives replacement if we just need .name, .id, .ts
Returns list of borg.helpers.ArchiveInfo instances
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring style:
"""
like
this
"""
or
"""like this"""

Comment thread src/borg/archiver.py Outdated
if not archives:
logger.critical('There are no archives.')
self.exit_code = self.exit_code or EXIT_WARNING
return []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the complete if-block, it is rather harmful than doing anything good.
if archives is empty here, the rest of the code here will still work normally and return a empty list at the end, no special casing needed.

@ThomasWaldmann

Copy link
Copy Markdown
Member

@funkyfuture if we can finish this quickly, it can go into 1.1.0b2 still, release is tomorrow.

@funkyfuture

funkyfuture commented Sep 30, 2016 via email

Copy link
Copy Markdown
Contributor Author

@ThomasWaldmann

Copy link
Copy Markdown
Member

Cool, thanks.

These are: --sort-by, --first and --last

Includes a method to obtain a list of archive infos filtered by these

Archives.list:
- ensure reverse is always applied
- always return a list
- adds prefix argument to helpers.Archives.list
- also renames function PrefixSpec to prefix_spec
@funkyfuture

Copy link
Copy Markdown
Contributor Author

can you give me a hint what is suddenly causing this:

user@host:~/python/borg (archives_filters) $ borg init --encryption=none /tmp/test
self test test_iteritems (borg.testsuite.hashindex.HashIndexTestCase) FAILED:
Traceback (most recent call last):
  File "/home/user/python/borg/src/borg/testsuite/hashindex.py", line 91, in test_iteritems
    self.assert_raises(StopIteration, next, iterator)
  File "/usr/lib/python3.5/site-packages/_pytest/python.py", line 1202, in raises
    pytest.fail(message)
  File "/usr/lib/python3.5/site-packages/_pytest/runner.py", line 537, in fail
    raise Failed(msg=msg, pytrace=pytrace)
Failed: DID NOT RAISE <class 'StopIteration'>

self test failed
This is a bug either in Borg or in the package / distribution you use.

@enkore

enkore commented Sep 30, 2016

Copy link
Copy Markdown
Contributor

Recompile the extensions (python setup.py develop or pip install -e .); it seems we forgot to bump the API_VERSION of hashindex there (#1659).

@funkyfuture

Copy link
Copy Markdown
Contributor Author

i incorporated the demanded changes, but did not squash these as the effort and risk to break things are too high.

@ThomasWaldmann

Copy link
Copy Markdown
Member

./src/borg/testsuite/archiver.py:1830:5: E303 too many blank lines (2)

@ThomasWaldmann

Copy link
Copy Markdown
Member

lgtm modulo test results.

@funkyfuture

Copy link
Copy Markdown
Contributor Author

got it.

@ThomasWaldmann ThomasWaldmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Code definitely more clean now.

Please note that there are some followup tickets with bounties on the issue tracker.

@ThomasWaldmann

ThomasWaldmann commented Sep 30, 2016

Copy link
Copy Markdown
Member

2 related issues with bounties:
#1663
#1542

@ThomasWaldmann
ThomasWaldmann merged commit f38c25d into borgbackup:master Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants