Making backups with BTRFS snapshots
- Install snapbtr
There is a number of different helpers for the automatic snapshoting a btrfs volume. Assuming that we want to create a snapshot before offlineimap syncs it’s data, the best place to call such a tool is hook scripts.
But almost all these helpers require root permission, which is not acceptable for us (unless you are running offlineimap as root).
The snapbtr fits this requirement. It separates creating snapshots (no root needed) from cleaning-up (root required).
To install, follow the instructions on the project page
- Create a workspace
This approach requires serveral components. Let’s keep them together in one folder
- Prepare the storage
In this setup, the “store” folder is inteded to keep your Maildir(s). So you would need to provide the path to it in your ~/.offlineimaprc file. For example:
IMPORTANT: if you already had offlineimap configured with this account, you need to check if your offlineimap version is newer then 7.0.0. Or there is a high risk of wiping your emails on the server. Check the FAQ for more details.
- Setup the hook
Create a script
And, finally add the path to the hook script into your ~/.offlineimaprc file into the Account section. For example:
In this example we used offlineimap’s hook. However there are other options, because offlineimap is just an email fetcher, and usually there are more applications in the final email stack. For example, if you are using notmuch, much better way to make your snapshots would be using its “pre-new” hook. This way you will be backuping not only offlineimap’s data, but notmuch’s database as well.