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?


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/.

| improve this answer | |
  • 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 '16 at 11:15
  • This also worked using MSYS/MINGW on Windows. +1 – linux64kb May 16 '19 at 18:27

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.



| improve this answer | |

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 <theodore@phpexperts.pro>
# 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;
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.