notmuch support #264
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#264
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
One of the things that's creating the most "churn" (as in, needless changes and transfers) in my borg backups is notmuch mail. It's a great piece of software, but one of its ... peculiarities is it can create pretty big databases. Before "compaction" here, the (Xapian) database was 12GB. But after compaction, it drops down to 2GB, which is still pretty big.
That database can also change during backup, obviously, which is bad news for a consistent restore.
I would like to backup this thing properly. From what I understand, the "proper" way of doing a backup of a notmuch database is to create a text only copy of the database, with
notmuch dump
and copy the relatedMaildir/
spool (which is indexed in the huge database). In my home-made scripts, I do basically this:That's a simplified view, of course. Is this something I should implement directly in borgmatic, or should I use some existing pre/post hook system instead?
Thanks!
I'd certainly consider support for this directly in borgmatic, especially since I think it'd be pretty straight-forward to add. Let me know if you'd like to take a crack at implementing this yourself!
i would love some guidance on how to do this. an example commit adding similar functionality would greatly help, along with some pointers on where the code should be added, how to write unit tests (if that's necessary) and so on... thanks!
Sure thing! Here's an overview of the entry points and call flow:
dump_database()
in each of the per-database source files.remove_database_dumps()
on the per-database source code.borgmatic restore
command is run explicitly. This effectively callsmake_database_dump_patterns()
andrestore_database_dumps()
on the per-database source code.Hopefully, you shouldn't need to change any of that. But the context should be helpful.
In terms of what you'd need to add:
generate-borgmatic-config
to try out your schema changes and make sure they get rendered as you expect. Also add the hook name (e.g.notmuch_databases
) to the list of database hook names.borgmatic/hooks/notmuch.py
source file and implement each ofdump_databases()
,remove_database_dumps()
,make_database_dump_patterns()
, andrestore_database_dumps()
. By way of example, here's the existing module for MySQL. You'll notice that for some functionality, it makes use of a common dump.py file of utility functions common to multiple database types. Also, don't forget to add your newly created module to the mapping of configuration hook name to Python module name.test_notmuch.py
in that directory. borgmatic uses flexmock as its test framework.borgmatic create
andborgmatic restore
should all work as expected. Including error cases where dumps aren't present, etc.I know this sounds like a lot, but I think (hope!) that it's really pretty straight-forward. And of course let me know if anything here isn't straight-forward, or you need some help. WIP PRs are welcome.
your reply sounds like a great addition to the "reference" section. ;) and yes, it does seem like a lot, but I guess that's the price to pay for inclusion, and I respect that! i'll see what i can do.
thanks for the detailed reply!
I'll see if I can distill something down for reference or the development guide.
If it turns out that you only get part-way through this, that's totally fine. I'm happy to pick up from there. I'm just happy to get contributions!
minimal progress here: I've hooked notmuch into the pre/post
hooks
system, like this:I was hoping that
pv
would work here, but alas, it seems the hook output gets swallowed somehow and doesn't show up, which is strange because theecho
do show up. maybe standard error is hidden in hooks?I'm not sure I'll be able to implement a native plugin for notmuch. It is kind of a corner case and maybe it's better to use this simple hook instead...
it would sure be nice to have better integration with the borg flags... like right now the above always shows the "echo" output, regardless of verbosity... same with the
pv
progress bar which does not get shown (yet should show up with--progress
). :) but i guess that's a minor tradeoff compared with the work involved in coding all of this...sorry, i wish i had more time, but i was able to scratch that itch without going through anything complicated, so maybe that's for the best. :)
I'm glad to hear that the command hooks are (mostly) working for you here. Custom preparation/cleanup commands are certainly what they're there for!
As for the
echo
showing up regardless of verbosity, that's by design. With the exception of error hooks, all hook output is logged at a level such that it shows up all at all verbosities except-1
. The idea is that if you're running custom commands, you probably don't want their output swallowed. So you could switch to--verbosity -1
if you really don't want to see it. Or, you know, remove theecho
. 😄And I'm pretty sure that the
pv
progress bar doesn't work because borgmatic captures the hook command output and therefore doesn't give commands likepv
access to an interactive terminal where they can redraw the display. The purpose behind capturing output is so that it can flow properly to logs (whether console, syslog, or file).Of course, there'd be more flexibility to change how this works with a "native" hook.. But I totally recognize the trade-off there in up-front effort.
that all makes sense! :) thank you in any case for all your help and i hope that your work of documenting how to possibly do this will be useful for future people looking into this problem, for notmuch or else...