You are not logged in.

#1 2021-09-20 03:19:38

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

[SOLVED] How to get back deleted pacnew files

I accidentally deleted some pacnew files using pacfiles-mode. Is there any way to get these files back? I don't know the name of what I deleted.

Solution.

Last edited by ThinkPad (2021-09-23 16:43:59)

Offline

#2 2021-09-20 03:26:15

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] How to get back deleted pacnew files

Reinstalling the package will create a pacnew.

Your pacman log has a record of them.

Last edited by jasonwryan (2021-09-20 03:27:27)


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2021-09-22 14:48:19

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

Re: [SOLVED] How to get back deleted pacnew files

Sweet, thanks!

To document the solution:
1. List all pacnew files that have ever touched your system:

$ grep --extended-regexp "\.pac(new|save)" /var/log/pacman.log

2. Search for what package owns the file in question with:

$ pkgfile <file>

3. Reinstall the package:

# pacman -Syu <package>

Sources:
https://wiki.archlinux.org/title/Pacman … pac*_files
https://bbs.archlinux.org/viewtopic.php … 65#p704765

Offline

#4 2021-09-22 15:15:15

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

Re: [SOLVED] How to get back deleted pacnew files

After doing what I listed, no new pacfiles show up in the log nor are detected by my tool. This was checked before and after reboot.

Offline

#5 2021-09-22 16:08:35

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,544

Re: [SOLVED] How to get back deleted pacnew files

You would have to downgrade and upgrade again. pacnew files are only created if something changed between the package installed and the one being installed.

Online

#6 2021-09-23 16:42:32

ThinkPad
Member
Registered: 2019-01-29
Posts: 125

Re: [SOLVED] How to get back deleted pacnew files

Thank you!

Updated solution:
1. List all pacnew files that have ever touched your system:

$ grep --extended-regexp "\.pac(new|save)" /var/log/pacman.log

2. Note the date of the pacnew in question.

3. Search for what package owns the file in question with:

$ pkgfile <file>

4. Search your cache for the version prior to that date:

$ find /var/cache/pacman/pkg -iname *<package>*

In my case downgrading to the oldest version in the cache was most reliable. That being said, you can skip step 2.

5. Downgrade to that package:

# pacman -U /var/cache/pacman/pkg/<old-package>

NOTE: Be very careful downgrading `pacman`. I did and was not able to perform a system upgrade. Using `pacman-static` got me out of trouble.

6. Upgrade package to force pacnew creation:

# pacman -S <package>

I did this at each interval to avoid putting my system in a broken state. You might get away with doing a full system upgrade at the end.

Sources:
https://wiki.archlinux.org/title/Pacman … pac*_files
https://bbs.archlinux.org/viewtopic.php … 65#p704765
https://wiki.archlinux.org/title/Downgrading_packages

Offline

#7 2021-09-23 16:57:55

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

Re: [SOLVED] How to get back deleted pacnew files

You should be able to handle this without down/upgrading - especially if you already know which files you're looking for as you can just extract them from the current package file.  I have this little script to extract a given file from the current cached package file for a given package (downloading it from a mirror only if it is missing from the local cache):

#!/bin/sh

[ $# -lt 2 ] && exit 1

uri=$(pacman -Sp $1)
path=$(pacman -Flq $1 | grep -m 1 /$2$)

[ -z "$uri" ] && exit 1
[ -z "$path" ] && exit 1

curl -sL $uri | bsdtar xOf - $path

Just pass a package name and a filename and the default content (which is what a pacnew would contain) is printed to stdout.

Last edited by Trilby (2021-09-23 16:59:32)


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

Offline

Board footer

Powered by FluxBB