9

On Arch Linux, I've backed up my system with rsync and restored it again, but it seems that my way of doing it (which I did get from the Arch Wiki but must be wrong?) has kept old files deleted by Pacman. This results in the error duplicated database entry when I try to upgrade my system with pacman -Syu. What should I do?

4 Answers 4

12

I suggest that you read the information in the links here and here.

Basically, you need to remove the duplicates (manually or using a script) from /var/lib/pacman/local/.

2
  • Thanks, this seems to have worked. I couldn't get the script to work though, so I had to do it manually.
    – Toothrot
    Oct 6, 2016 at 11:15
  • This also worked using MSYS/MINGW on Windows. +1
    – linux64kb
    May 16, 2019 at 18:27
3

I just went through this. You need to us the rsync --delete option. The Arch wiki is wrong about the --delete option altering anything in the source system. It will only delete files in destination if they have been deleted or are not in source. This will also prevent a bunch of unwanted files building up if you run the backup on a regular basis.

Source1

Source2

5
1

I tried @Schooled and @maulinglawns answers but both basically bricked my system.

The reason is that source was running linux-5.4.71 and dest was running linux-5.4.72, released just a day apart.

When rsync --delete ran, it deleted all of the kernel modules on dest/lib/5.4.72/, which basically led to a bricked system that was incapable of mounting critical file systems, among other things.

After restoring from my btrfs snapshot (thank God!!), I figured out the following solution:

# From https://github.com/hopeseekr/BashScripts/blob/master/arch-pacman-dupe-cleaner
# Copyright © 2020 Theodore R. Smith <[email protected]>
# GPG: 4BF8 2613 1C34 87AC D28F  2AD8 EB24 A91D D612 5690
# License: Creative Commons Attribution v4.0 International
# @see https://unix.stackexchange.com/a/615578/15780

# 0. Login as root.
sudo -s

# 1. Remove the latest dupes from your Pacman DB.
pacman -Syu 2>&1 | grep "duplicated database entry" > /tmp/dupes
for latest in $(for dupe in $(cat /tmp/dupes | awk '{print $5}'); do
    ls /var/lib/pacman/local/$dupe* -d | tail -n1; done); do
    rm -rvf $latest;
done
rm /tmp/dupes

# 2. Remove system of dupe files.
pacman -Syu 2>&1 > /tmp/update-dupes
cat /tmp/update-dupes | grep "exists in file system" | awk '{print $2}' | xargs rm -vf

# 3. Reinstall everything (this will restore anything deleted in #2.).
pacman -Syu

Since this is quite a lot, I have added it to my BashScripts repository as arch-pacman-dupe-cleaner.

1

This command worked for me after changed directory to /var/lib/pacman/local:

ls | sort | awk -v re='(.*)-[^-]*-[^-]*$' 'match($0, re, a) { if (!(a[1] in p)){p[a[1]]} else {print} }' | xargs sudo rm -rf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .