Pamac creates btrfs snapshots for each AUR package seperately even when installing together

Steps to reproduce:

  1. Mark a number of packages for installing from official repos and AUR (in my case, it was update)
  2. Click ‘Apply’

Observed results:
Before installing packages from official repos, a single btrfs snapshot is created. Before installing each package from AUR, a new btrfs snapshot is created.

Intended Results:
Only a single btrfs snapshot is created before the entire operation irrespective of number of packages or repository of the packages

The issue is that snapshots created immediately one after another makes the operation much slower (i guess it takes more time to calculate diffs? Idk exactly but it stays on snapshot creation step for few minutes when time gap between them is less). Also, it replaces other older snapshots with those that are barely few minutes apart.

So is there a way to resolve it or should I create a gitlab issue?

The snapshot is not created by pamac but timeshift when the package operation is Upgrade.

 $ cat /usr/share/libalpm/hooks/00-timeshift-autosnap.hook 
[Trigger]
Operation = Upgrade
Type = Package
Target = *

[Action]
Description = Creating Timeshift snapshot before upgrade...
Depends = timeshift
When = PreTransaction
Exec = /usr/bin/timeshift-autosnap
AbortOnFail

Local package - e.g. one build from AUR - is installed with the -U argument which triggers the hook

 $ man pacman
[...]
       -U, --upgrade
           Upgrade or add package(s) to the system and install the
           required dependencies from sync repositories. Either a URL or
           file path can be specified. This is a “remove-then-add”
           process. See Upgrade Options below; also see Handling Config
           Files for an explanation on how pacman takes care of
           configuration files.
[...]

so is there a way to modify this alpm hook to not have this behaviour? I don’t think its a timeshift feature since it is bundled by timeshift-autosnap-manjaro package, which i guess was made by manjaro

No - but you can uninstall the package - and maintain your snapshots manually

If I am not wrong though, pamac’s AUR capabilities are not based off on pacman, so why does updating AUR packages trigger that hook in first place?

Read my comment above - quoted here

and because pamac uses libalpm when adding and removing packages.

So if i am understanding it correctly, updating repo packages is like remove package A,B,C,D etc, followed by install package A,B,C,D etc. But in case of AUR apps, it is remove package A, install package A, remove package B, install package B and so on. So snapshot is created only once for packages from official repos, but each time for AUR. At what level does one modify to change this behaviour with AUR packages? Is it pamac or libalpm?

You cannot change the behavior because libalpm is designed that way (upstream Arch Linux) so whether you like it or not - the update (which is the only way of adding custom packages) will trigger the timeshift hook.

sudo pacman -U pkgname-version-pkgrel.pkg.tar.zst

Either remove the autosnap package and the script, config and hook or edit the configuration to disable autosnap.

Either way you will have to maintain your snaps manually and nothing you say or do can change that.

One completely different approach is to create a custom repo and add your custom packages to such repo. It doesn’t have to be on a remote server it can run locally of localhost:8080 - the benefit in your use case is that libalpm will see it as one transaction instead of two or five or how many you have.

1 Like

There is an alternative solution:

Delete the unwanted snapshots after the update with your own script.

Why ?

Why create a snapshot first and then delete it?

Taking snapshots in BTRFS is cheap (check out the Btrfs wiki)

If you get too many snapshots, you can easily delete them with a script after the update. The script can select any snapshot to keep or discard.
:footprints:
(Wisdom lies in asking → listening → reading :wink: )

thats the thing. when new snapshots are created, they delete the older ones automatically. So one ends up with all snapshots that are few minutes apart. Also, I know it should be easy, but when snapshots are taken one after another, they take a lot of time to make. These are the two issues I have as I said above, besides that this doesn’t feel the right way of doing things

I have not made repos before, but I will see if this works out.

What I fail to see is that why multiple packages can’t be passed on together, so

sudo pacman -U pkgname-version-pkgrel.pkg1.tar.zst pkgname-version-pkgrel.pkg2.tar.zst pkgname-version-pkgrel.pkg3.tar.zst

That should make invoke the timeshift hook just once

Well you can test it - use makepkg to build two custom packages - then move the packages to a shared folder and execute the pacman command inside the shared folder.

If it turns out that it only triggers the hook one time - then you have grounds to suggest an improvement to pamac.

But as pamac uses libalpm which is upstream Arch LInux - I would not get my hopes up :slight_smile:

1 Like

If you can get the date and time of the latest snapshot, you could have the hook call a custom script which compares it to the current date/time, and only makes a snapshot if a certain amount of time has passed.

2 Likes

Pamac already installed built packages in one row if it’s possible. The problem is that if you want to build package A that depends on package B, you need to build and install package B before building package A. It’s something you can’t see by installing already built packages from repos.

2 Likes

yeah, i tried it and it only required it once. I will make a bug report for it, but @dmt makes a good point that should be solved at level of timeshift-autosnap-manjaro ideally

that crossed my mind too but won’t that be sorted in the first place when it checks for dependencies and makes the list of changes (installed/removed) to be made? This is the final step when the AUR script has executed and built a package

To be clear, the hook is from timeshift-autosnap-manjaro. not timeshift itself.

There is a single transaction for every packages available from the repos then Pamac build packages and, when finished or when needed between two builds, run one transaction to install them.

Install Topgrade and avoid the BS all together. I’ll have 3 or 4 AUR apps to be built and upgraded and Topgrade just downloads them, builds them, ask if I want to install, and does one single snapshot. Now that said if I have a dozen precompiled programs to be updated before their installed there will be a snapshot created, then the AUR programs will be done.

Much easier and faster to launch Timeshifts GUI and delete the snapshots you don’t want from there.

I think timeshift-autosnap-manjaro has an option to stop creating btrfs snapshot.
:point_down:

$ SKIP_AUTOSNAP=true pamac build {AUR_PACKAGE}

See the document: