digint / btrbk

Tool for creating snapshots and remote backups of btrfs subvolumes
https://digint.ch/btrbk/
GNU General Public License v3.0
1.72k stars 124 forks source link

Working on pacman hook for Arch Linux #412

Open MountainX opened 3 years ago

MountainX commented 3 years ago

I am working on pacman hooks that use btrbk to create pacman pre/post btrfs snapshots on Arch Linux. I did not find any existing btrbk package for pacman hooks, so I am working on it myself.

Assume this package will be named btrbk-pac. (Although btrbk-pacman-hook is another option. Suggestions?)

The pre-hook and post hook will look like the following:

# cat /usr/share/libalpm/hooks/05-btrbk-pac-pre.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk pre-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PreTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always
NeedsTargets
AbortOnFail

# cat /usr/share/libalpm/hooks/zz-btrbk-pac-post.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk post-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PostTransaction
Exec = Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always
NeedsTargets

How does that look?

The btrbk command in the hooks filters on "root". It depends upon the btrbk.conf file having a "root" item defined. That config item that matches the filter can be a group-name, volume-directory, etc. as per the btrbk man page. (I would recommend configuring a "root" group in the btrbk.conf file for this hook.)

I asked a related question on the pre-hook on the Arch Forum here: Working on pacman hook for btrbk. How to skip action on removing pkg? / Creating & Modifying Packages / Arch Linux Forums

I appreciate any suggestions or feedback.

MountainX commented 3 years ago

There were a few typos in the earlier post. I have a working version now. (At least it works for me.)

I'm posting everything here in case anyone wants to put it in the AUR:

filename: 05-btrbk-pac-pre.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk pre-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PreTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always

filename: zz-btrbk-pac-post.hook

[Trigger]
Operation = Upgrade
Operation = Install
Operation = Remove
Type = Package
Target = *

[Action]
Description = Performing btrbk post-pacman snapshots for the following configurations...
Depends = btrbk-pac
When = PostTransaction
Exec = /usr/bin/btrbk run root --preserve --override=snapshot_create=always

filename: PKGBUILD

# Maintainer: TODO
# Contributor: TODO

pkgname=btrbk-pac
pkgver=1.0.r4
pkgrel=1
pkgdesc="pacman hooks that use btrbk to create pre/post btrfs snapshots"
arch=('any')
url="TODO"
license=('GPL')
depends=('btrbk')
makedepends=('git')
source=("git+${url}")
sha256sums=('SKIP')

package() {
  cd "$srcdir/${pkgname}"

    install -m 0755 -d $pkgdir/usr/share/licenses/$pkgname
    install -m 0644 LICENSE $pkgdir/usr/share/licenses/$pkgname

    install -m 0755 -d $pkgdir/usr/share/doc/$pkgname
    install -m 0644 README.md $pkgdir/usr/share/doc/$pkgname

    install -m 0755 -d $pkgdir/usr/share/libalpm/hooks
    install -m 0644 05-btrbk-pac-pre.hook $pkgdir/usr/share/libalpm/hooks
    install -m 0644 zz-btrbk-pac-post.hook $pkgdir/usr/share/libalpm/hooks
}

filename: README.md

# btrbk-pac

pacman hooks that use btrbk to create pre/post btrfs snapshots on Arch Linux

filename: LICENSE
Any license can be used, but a file by this name is required by the PKGBUILD

Note: I am thinking of adding the --quiet option to the Exec command in the hooks. Currently, the btrbk output is shown in the pacman stdout. That was nice during testing, but it may be a bit much on continued use.

MarkoPaasila commented 3 years ago

btrbk-pacman-hook is self-explanatory, unique, and good

MountainX commented 3 years ago

Earlier I said:

The btrbk command in the hooks filters on "root". It depends upon the btrbk.conf file having a "root" item defined. That config item that matches the filter can be a group-name, volume-directory, etc. as per the btrbk man page. (I would recommend configuring a "root" group in the btrbk.conf file for this hook.)

Now that I've been using these hooks, I have changed that detail. I hard-coded the filter as "btrbk-pac". This requires that the user add a group (or some other filterable item) of the name "btrbk-pac" to their btrbk.config file. It's a very simple step and it is very configurable since you can define multiple groups per group item, and one could add a "btrbk-pac" group to one or more different items (volumes, subvolumes). I suppose one could even define targets or directories using the name "btrbk-pac".

Also in regard to naming, since I decided on the above change, I also decided to name the package itself "btrbk-pac". (Although between btrbk-pac, btrbk_pac and btrbkpac, I'm still undecided.)

Also, btrbk itself uses a creative, short and "cute" naming approach (as opposed to, say, "btrfs backup", so I thought it would be in the same spirit to use "btrbk-pac" instead of "btrbk-pacman-hook". Anyway, if anyone wants to change the name and create an AUR package, I will not object.

NovaViper commented 2 years ago

@MountainX Where is the AUR package located? I want to try to use this on my system

daiaji commented 1 year ago

I added a systemd timer unit on the basis of "btrbk-pac". The function is equivalent to snapper-boot.timer, which is used to generate a snapshot when booting. There are plans to add an AUR package, but I should change the package name to "btrbk-hook" (because this package not only includes pacman hook), the protocol uses the same gpl-3.0 as btrbk, because the snapper-boot.timer and snapper-boot.service of the snapper package are used, I think the protocol may only be able to use gpl.

But I need to do more testing before releasing this AUR package.