You are not logged in.

#1 2014-01-09 21:40:13

Sternmull
Member
Registered: 2009-09-22
Posts: 22

Can I run hooks before pacman transactions?

I want to create a snapshot of my system everytime before pacman starts to make a modification. There is something in the wiki that talks about this. But the man page does not mention anything about it. So it seems this feature is not yet implemented. Or did I missed something in the documentation? Or is it implemented but not documented?

Offline

#2 2014-01-09 22:58:08

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Can I run hooks before pacman transactions?

Hooks are on one of the todo lists somewhere. They've been discussed on the pacman-dev mailing list a few times. I think that I have seen them mentioned on Allan's blog too.

Until they're implemented, you'll just have to write a wrapper script that creates a snapshot before running pacman commands that can modify the system (basically just -S, -R and -U, minus query options for each operation... I doubt that -D matters).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#3 2014-01-10 06:41:35

Sternmull
Member
Registered: 2009-09-22
Posts: 22

Re: Can I run hooks before pacman transactions?

Thank you. A wrapper script is not perfect because it can not know if pacman will actually do something. If I call "pacman -Syu" for example the script will not know if pacman will just tell that everything is up to date or if it will do some real work. The same happens if i do "pacaman -S misstyped-package-name".

So for now I will probably stick with manually triggered snapshots or I will do time based scheduling.

Offline

#4 2014-01-10 09:27:46

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: Can I run hooks before pacman transactions?

You could use shell aliases. First run the alias without the snapshot command, and if updates are found, run the one with the snapshot command.

Or you could parse pacman's output (or check exit codes), and write a script to take a snapshot according to a given condition.

for example, pacman -S gives an exit code of 1 with a wrong package name.

Offline

#5 2014-01-10 14:28:02

Sternmull
Member
Registered: 2009-09-22
Posts: 22

Re: Can I run hooks before pacman transactions?

As I do "pacman -Syu" regulary, it would be enough to create a snapshot for exactly this command (by using a scipt that calls pacman and does my snapshot magic). So I would probably be happy if I would have a script that makes sure a snapshot exists for every point before i changed my system by this command. Because BTRFS snapshots are cheap it would even be ok if it would create a snapshot everytime before the command runs and deletes it afterwards if it did nothing.

Unfortunately I see no easy way to detect if pacman did something. Exit codes are not documented and there is no way to make its output machine-readable-friendly. Probably creating a complete list of the installed packages before and after pacman would allow to detect system-changes by comparing them. Maybe I will go that way... but hooks would be much nicer!

Offline

#6 2014-01-10 22:39:41

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: Can I run hooks before pacman transactions?

While you wait for hooks, read about -Qu -q -Sl in the man page:

It is easy to wrap -Syu to :

pacman -Sy
pacman -Qu >/dev/null && /path/to/your/snapshot/script
pacman -Su

to know if package foo is available in the repos you can just run

pacman -Sql | grep ^foo$

so you can wrap just wrap your "pacman -S $pkg" to

! pacman -Qq $pkg >/dev/null 2>&1 && pacman -Sql | grep -q ^$pkg$ && /path/to/your/snapshot/script
pacman -S $pkg

Offline

#7 2014-01-10 23:04:54

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Can I run hooks before pacman transactions?

@aesiris
I don't think this would be of much use, since even updating a package can break the system. If you can't boot because of something related to e.g. your bootloader, you need to have a way of rolling back this change.

Sternmull wrote:

it would create a snapshot everytime before the command runs and deletes it afterwards if it did nothing.

If you update weekly, rarely there will be a week, w/o any updates, even if you have a minimal system.

Offline

#8 2014-01-11 09:22:15

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: Can I run hooks before pacman transactions?

@karol

Of course I agree that a wrapper script is not a substitute for a pacman hook, but I don't understand why you say that this will not work.
Assuming that OP's script creates a good snapshot (e.g. it would include a copy of /boot), why is it not enough to wrap "pacman -S foo" and "pacman -Syu"?

Offline

#9 2014-01-11 09:45:07

Sternmull
Member
Registered: 2009-09-22
Posts: 22

Re: Can I run hooks before pacman transactions?

@aesiris: About "pacman -Qu" the man page says "Only package versions are used to find outdated packages, replacements are not checked here". So I suspect it to miss some update scenarios. Its more safe to create the snapshot, run "pacman -Q" to list all installed packages including their version, run the real pacman command (-Syu or whatever), run "pacman -Q" again and compare the output: If its the same as in the first one then delete the snapshot.

But as karol writes it is very unlikely that pacman -Syu will do nothing for days. So it could make more sense to make time based snapshots. This is no bad idea because pacman is not the only thing that causes system changes.

Offline

#10 2014-01-11 09:59:20

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Can I run hooks before pacman transactions?

You can change a config file, remove some important file etc. etc. If something breaks, it doesn't have to be pacman, it may be just PEBKAC :-)
Logging pacman's output doesn't hurt, but COW-snapshotting is good on its own.

Offline

#11 2014-01-11 10:18:38

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Can I run hooks before pacman transactions?

karol wrote:

but COW-snapshotting is good on its own.

photogvbull1_mini.jpeg
"Stay away from my wife, snowflake."


This silver ladybug at line 28...

Offline

#12 2014-01-11 10:45:39

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Can I run hooks before pacman transactions?

Wow.
I'm honestly amazed you found such a fitting photo. Perfect.

I love the caption too :-)

Offline

Board footer

Powered by FluxBB