You are not logged in.
Hi,
I have a cron job that backs up several important files to an external HDD. Besides the usual things like /home and /etc, I make it backup the contents of /var/lib/pacman.
Last week my old netbook died of old age and now that I am getting a new one I wanted to replicate my setup. I am unable to make it boot, I don't know if it's the battery or something else; the thing is I don't want to invest any more time on it. I would like to know how to extract the list of _explicitly_ installed packages (something like pacman -Qeq) from the contents of the /var/lib/pacman backup.
I thought of creating a virtual arch installation and copying /var/lib/pacman and then to issue the pacman -Qeq command. But I feel it is a little destructive, so I was wondering if there is a better way of interrogating the /var/lib/pacman backup to extract this information. Something like, for example, telling pacman the location of its database.
Any help would be highly appreciated. Thanks in advance.
Last edited by TioDuke (2019-02-14 03:59:13)
[img]http://boincstats.com/signature/-1/user/2670943/sig.png[/img]
Offline
Something like, for example, telling pacman the location of its database.
Have you tried the --dbpath option?
Offline
Or if that doesn't work:
for f in $path_to_old/var/lib/pacman/local/*/desc; do sed -n '/%NAME%/{n;h;}; /%REASON%/q; ${x;p;};' $f; done
Or with gnu sed you could use the following slightly more efficient approach:
sed -sn '/%NAME%/{n;s/^/:/;h;}; /%REASON%/{x;s/^://;x}; ${x;s/^://p;};' $path_to_old/var/lib/pacman/local/*/desc
Frustratingly, while gnu sed adds an option to process multiple files seperately rather than as a single unified stream, it does not include any command to quit just the current file processing and/or move on to the next file like gawk's 'nextfile' command. So the actual sed script for the gnu-ifed version is a bit more cumbersome.
And in case anyone wants the gawk version, it turns out 'nextfile' isn't actually helpful here as ENDFILE blocks still execute:
gawk '/%NAME%/{getline pkg;} /%REASON%/{ pkg=0; }; ENDFILE { if (pkg) print pkg;}' /var/lib/pacman/local/*/desc
Last edited by Trilby (2019-02-14 02:38:58)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Thank you. --dbpath did the trick.
[img]http://boincstats.com/signature/-1/user/2670943/sig.png[/img]
Offline