You are not logged in.

#1 2020-11-02 12:20:57

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

[Solved] pacman hook - supress stderr

I want to create a hook that creates a backup of my /etc folder:

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

[Action]
Description = Backup etc folder
When = PreTransaction
Exec = /usr/bin/tar --acls --xattrs -cpf --warning=no-all /home/icar/etc-backup.tar.gz /etc

This works, but I get annoying warning lines from tar. So, basically the '--warning=no-all' doesn't work. Neither does '--warning=none' or '2>/dev/null'.
Is this some libalpm's hooks limitation? If so, is there any way to redirect stderr?

I've been reading alpm-hooks(5) and some tar manuals. This is where I got.

Last edited by icar (2020-11-02 17:01:45)

Offline

#2 2020-11-02 12:59:08

GaKu999
Member
From: US/Eastern
Registered: 2020-06-21
Posts: 696

Re: [Solved] pacman hook - supress stderr

You could wrap it into a script in /etc/pacman.d/scripts and redirect in it stderr to /dev/null. Remembering to have the script as +x
(Also there's etckeeper, in that case you would only need a backup of the vcs repo)

You also can do it directly by enclosing the whole exec as args for /usr/bin/sh -c "<codehere> 2>/dev/null".

Last edited by GaKu999 (2020-11-02 13:09:05)


My reposSome snippets

Heisenberg might have been here.

Offline

#3 2020-11-02 13:13:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [Solved] pacman hook - supress stderr

What are the warnings you are getting?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2020-11-02 15:32:04

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: [Solved] pacman hook - supress stderr

Trilby wrote:

What are the warnings you are getting?

/usr/bin/tar: Removing leading `/' from member names
/usr/bin/tar: Removing leading `/' from hard link targets
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.browser: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.extra: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.dirmngr: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.ssh: socket ignored
GaKu999 wrote:

You could wrap it into a script in /etc/pacman.d/scripts and redirect in it stderr to /dev/null. Remembering to have the script as +x
(Also there's etckeeper, in that case you would only need a backup of the vcs repo)

You also can do it directly by enclosing the whole exec as args for /usr/bin/sh -c "<codehere> 2>/dev/null".

The last suggestion would be preferred as I want it to keep it simple (just a hook). Trying that right now...

... And *yes*! The output gets redirected. Thank you very much, I need to keep in mind that "trick" in the future.

Now, the question would be why '--warning=no-all' or '--warning=none' is not working when called in a hook.

EDIT: The output does get redirected, but further checks showed me the file fails to be created. I removed the redirection keeping the execution of the command as an argument and the error is

/usr/bin/tar: Removing leading `/' from member names
/usr/bin/tar: /home/icar/etc-backup.tar.gz: Cannot stat: No such file or directory
/usr/bin/tar: Removing leading `/' from hard link targets
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.browser: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.extra: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.dirmngr: socket ignored
/usr/bin/tar: /etc/pacman.d/gnupg/S.gpg-agent.ssh: socket ignored
/usr/bin/tar: Exiting with failure status due to previous errors
error: command failed to execute correctly

But it does work implemented in the same way that in the first post.

EDIT2: For some reason it just stopped working now. Not even how it used to work in the first post.

EDIT3: (Yeah, I'll stop with the edits now). Removing --warning flag makes it work again.

Last edited by icar (2020-11-02 15:53:17)

Offline

#5 2020-11-02 16:17:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,444
Website

Re: [Solved] pacman hook - supress stderr

Don't cover up the warnings, address them.  This will fix the first two:

Exec = /usr/bin/tar --acls --xattrs -cpf /home/icar/etc-backup.tar.gz -C / etc

You potentially could also use the -P flag to avoid those warnings and still include absolte paths, but this is not likely what you want.

The other four are all due to socket files, so you could try explicitly silencing those with "--warning=no-file-ignored" or simply exclude the gnupg sockets explicity (e.g., with --exclude).

EDIT: you had the "--warning=no-all" right after the f flag ... I'm not sure that'd work at all as that tells tart to make an archive file literally named "--warning=no-all" but does not specify any warning flags.  This would also explain the error about the tar file not being found when you are intending to create it: the command you actually used is using your etc-backup.tar.gz file as an input member along with /etc.

Last edited by Trilby (2020-11-02 16:22:37)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2020-11-02 16:57:40

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: [Solved] pacman hook - supress stderr

Trilby wrote:

Don't cover up the warnings, address them.  This will fix the first two:

Exec = /usr/bin/tar --acls --xattrs -cpf /home/icar/etc-backup.tar.gz -C / etc

You potentially could also use the -P flag to avoid those warnings and still include absolte paths, but this is not likely what you want.

The other four are all due to socket files, so you could try explicitly silencing those with "--warning=no-file-ignored" or simply exclude the gnupg sockets explicity (e.g., with --exclude).

EDIT: you had the "--warning=no-all" right after the f flag ... I'm not sure that'd work at all as that tells tart to make an archive file literally named "--warning=no-all" but does not specify any warning flags.  This would also explain the error about the tar file not being found when you are intending to create it: the command you actually used is using your etc-backup.tar.gz file as an input member along with /etc.

Thanks for the suggestion. I had already tried them all. With tthis hook

Exec = /usr/bin/tar --acls --xattrs -cpf --warning=no-file-ignored /home/icar/etc-backup.tar.gz -C / etc
(1/1) Backup etc folder
/usr/bin/tar: Removing leading `/' from member names
/usr/bin/tar: Removing leading `/' from hard link targets
/usr/bin/tar: etc/pacman.d/gnupg/S.gpg-agent: socket ignored
/usr/bin/tar: etc/pacman.d/gnupg/S.gpg-agent.browser: socket ignored
/usr/bin/tar: etc/pacman.d/gnupg/S.gpg-agent.extra: socket ignored
/usr/bin/tar: etc/pacman.d/gnupg/S.dirmngr: socket ignored
/usr/bin/tar: etc/pacman.d/gnupg/S.gpg-agent.ssh: socket ignored

Edit: I read your edit after posting. I edited so that it appears as following:

Exec = /usr/bin/tar --acls --xattrs --warning=no-file-ignored -cpf /home/icar/etc-backup.tar.gz -C / etc

And now it executes appropriately. That does the trick. Funny how wometimes worked, tho. Maybe only if it hadn't found a file... Anyway, marking as solved.

Last edited by icar (2020-11-02 17:00:42)

Offline

Board footer

Powered by FluxBB