You are not logged in.

#1 2011-08-18 08:38:56

zebulon
Member
Registered: 2008-10-20
Posts: 358

First major disaster :) recovery strategy

Hi,

After 15 years of using Linux and Unix, I have had my major blunder: starting a rm -rf /usr/lib command, when I just wanted to erase a temporary .so file I had put there for some purpose. I stopped the obnoxious command, but too late, and some files have already been deleted. Pacman and yaourt are broken (needs dependencies like libfetch.so). This is not that a big issue though, since my personal stuff is intact (and backed up anyway).

Now I have to think the strategy that will allow me to fix my system:

  1. Can I fix the system at this stage or do I need to reinstall?

  2. Can I generate a list of installed packages (repository and AUR) even if pacman is broken (ala pacman -Qa and pacman -Qma but another way) and my pakg cache is empty?

  3. In case I need to repair pacman, I was considering using an Archboot image and copy the lib files necessary to pacman to work in /usr/lib. Would that work?

If you have further recommendations, please let me know what is best. Thanking you in advance smile

Offline

#2 2011-08-18 09:07:30

siriusb
Member
From: Hungary
Registered: 2010-01-01
Posts: 422

Re: First major disaster :) recovery strategy

Better later than never. tongue Sometimes it's worth to make system backups. wink

Well, I'd chroot into the system from an arch install cd and reinstall pacman first. After that, I have no idea...

Offline

#3 2011-08-18 10:24:14

lucak3
Member
From: Italy
Registered: 2010-01-23
Posts: 72

Re: First major disaster :) recovery strategy

Download (with wget, curl...) the pacman package directly (and all the deps that you find missing), untar them in / taking care of the spurious files like .PKGINFO
then you can reinstall every package you find that doesn't work because of missing libs (if you have time you can go 'pacman -S $(pacman -Qq)' )
Remember that you need to avoid non repo packages, like AUR ones, because pacman won't find them


The Linux philosophy is 'laugh in the face of danger'. Oops. Wrong one. 'Do it yourself'. That's it. - Linus Torvalds

Offline

#4 2011-08-18 10:36:21

chemicalfan
Member
From: United Kingdom
Registered: 2011-05-25
Posts: 58

Re: First major disaster :) recovery strategy

There's a script somewhere in the Arch wiki that will rebuild a package list if you lose pacman, but I don't remember whereabouts it is, sorry!

Edit: Try this - https://bbs.archlinux.org/viewtopic.php?pid=670876

Last edited by chemicalfan (2011-08-18 10:42:23)

Offline

#5 2011-08-18 14:59:21

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: First major disaster :) recovery strategy

As usual the Arch community is great and very helpful. Thanks a lot guys!

Offline

#6 2011-08-18 15:09:33

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: First major disaster :) recovery strategy

chemicalfan wrote:

Many thanks. That is very interesting. My perl is rusty, but as far as I understand, not only it detects installed files and from which packages they belong, but it also gives a percentage of files installed for each package. Therefore, I should be able to detect my "broken" packages, since they would have a score comprised between 0 and 100%. Am I correct?

Offline

#7 2011-08-18 15:19:29

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: First major disaster :) recovery strategy

chemicalfan wrote:

There's a script somewhere in the Arch wiki that will rebuild a package list if you lose pacman, but I don't remember whereabouts it is, sorry!

Edit: Try this - https://bbs.archlinux.org/viewtopic.php?pid=670876

The particular script you reference is useful when /var/lib/pacman/local is compromised. The link to Xyne's script is far more useful in this scenario. Neat.

edit: So, after looking at Xyne's script more closely, he's trying to do something similar to what the lost-db script does. Still not quite useful here. I've taken his idea and created the following snippet which compares the local DB's filelists to the filesystem. You can specify a tolerance and only return packages which are below this tolerance, e.g. a tolerance of 90 means only show packages where <=90% of the files are present. You may get some false positives when this isn't run as root, but you can start with a tolerance of 100 and work your way down from there.

#!/bin/bash

declare curpkg= pkg= file=
declare -i tolerance=$1 filecount= hitcount=

summary() {
  local ratio=

  # boring
  if (( hitcount == filecount )); then
    return
  fi

  # under tolerance
  ratio=$(( hitcount * 100 / filecount % 100 ))
  if (( ratio < tolerance )); then
    printf '%-30s %-10s (%s%%)\n' "$pkg" "$hitcount/$filecount" "$ratio"
  fi
}

pacman -Ql | while read pkg file; do
  if [[ -z $curpkg || $pkg != "$curpkg" ]]; then
    summary "$pkg" "$hitcount" "$filecount"
    curpkg=$pkg
    hitcount=0
    filecount=0
  fi

  # skip directories
  [[ $file = */ ]] && continue;

  (( ++filecount ))
  [[ -e "$file" || -L "$file" ]] && (( ++hitcount ))
done

Example output...

$ filecheck 100
feh                            78/80      (97%)
linux-rampage-headers          1170/1171  (99%)
namcap                         46/49      (93%)

Here, feh and namcap are false positives because I'm not root. I really did delete a file from my kernel package so I can account for that.

Last edited by falconindy (2011-08-18 15:57:07)

Offline

#8 2011-08-18 16:18:02

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: First major disaster :) recovery strategy

Amazing! Many thanks, that would be very useful for me indeed.

Offline

#9 2011-08-18 16:50:24

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: First major disaster :) recovery strategy

Very nice, falconindy, thanks for that. Want to put it in the wiki, aur or someplace more accessible than the Newbie Corner?


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#10 2011-08-18 17:20:35

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: First major disaster :) recovery strategy

It's been githubbed. That's a verb, now. Use it freely.

Probably not worth making a fuss over this, as pacman -Qkq does something similar. oops.

Last edited by falconindy (2011-08-18 17:25:15)

Offline

#11 2011-08-18 18:23:19

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: First major disaster :) recovery strategy

falconindy wrote:

Probably not worth making a fuss over this, as pacman -Qkq does something similar. oops.

A pacman dev forgets the options to pacman? Scandalous! tongue


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#12 2011-08-19 07:58:04

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: First major disaster :) recovery strategy

Hi all!
I am the original poster and wanted to thank everybody for their help, I have been able to repair my system yesterday and it seems to work fine now. I shall see if I have other issues in the near future, but do not feel the need to reinstall from scratch at this stage.
Just one thing that was a bit difficult:

pacman -S $(pacman -Qq)

works, however it fails when there are AUR packages installed. Is there a way to exclude non-AUR packages? I know that pacman -Qm lists these local packages, but I would need the complementary. I looked at pacman options but did not find something like this. Is it possible to restrict by repository, maybe?

Last edited by zebulon (2011-08-19 07:58:30)

Offline

#13 2011-08-19 10:08:05

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: First major disaster :) recovery strategy

These are from my backup scripts.  I copied them from someone else.

This should create a file listing the installed packages without the AUR packages.  It just lists packages by name, without version numbers.

pacman -Qqe | grep -Fvx "$(pacman -Qqm)" > package_list

Creating a file listing just the AUR packages:

pacman -Qqm > aur_list

Offline

#14 2011-08-19 11:33:28

zebulon
Member
Registered: 2008-10-20
Posts: 358

Re: First major disaster :) recovery strategy

Thanks a lot thisoldman.

Offline

#15 2011-08-19 20:07:09

Llama
Banned
From: St.-Petersburg, Russia
Registered: 2008-03-03
Posts: 1,379

Re: First major disaster :) recovery strategy

A most useful read: http://simson.net/ref/ugh.pdf

For deleting I use file managers, unless the case is very special. Precisely for a reason like this.

Offline

Board footer

Powered by FluxBB