Unable to `dnf history rollback` to undo remove and all removed unused dependencies

,

I did sudo remove -y lua, thinking that it would remove lua and related packages!

It ended up deleting 4158 packages (including texlive , libre-office and several others in the displayed “unused dependency section”, which I am unable to recall). While the destruction was going on, I got panicked and tried to cancel the operation by Ctrl + c, to no relief, I forced end the terminal.

Now I did: dnf history list, and it shows

ID     | Command line                                 | Date and time    | Action(s)      | Altered
---------------------------------------------------------------------------------------------------
   339 | remove -y lua                                | 2024-04-23 00:42 | Removed        | 4158 ##
  1. How can get back everything to previous state?
  2. After getting the previous state, is it possible to just remove lua from dnf?
  3. How could one know what all other packages will be removed before removing the command? dnf info lua didn’t warn me of this!

Can you try : sudo dnf history rollback 339 ?

I knew about this, but was not sure if it also reverts all other 4158 packages. Can you please confirm this?

1 Like

Rolling back a transaction using dnf history rollback typically reverts all changes made by that specific transaction. In your case, ID 339 corresponds to the removal of lua and the subsequent removal of 4158 packages. Also, I did not include the -y so you should see it before it happens.

$ sudo dnf history rollback 339
Last metadata expiration check: 2:27:57 ago on Mon 22 Apr 2024 22:42:49 CEST.
Dependencies resolved.
Nothing to do.
Complete!

Nothing happened beyond the above message

You can verify the status of the transaction by running sudo dnf history info 339 to see if there are any error messages or additional information that might explain why the rollback didn’t work.

Please see the output at: https://0x0.st/Xo72.txt

Please see the output at: https://0x0.st/Xo72.txt

Well that sucks, You can take that info and make a script then reinstall all of the packages with a small bash script.


#!/bin/bash

# List of packages to reinstall (replace with the actual list from the transaction log)
packages=(

)

# Reinstall packages
for pkg in "${packages[@]}"; do
    sudo dnf install -y "$pkg"
done

Then save the file and make it executable.

chmod +x reinstall_packages.sh

I used vim to cleanup the file.

like so :

vim :%s/^ \*\* // & then :%s/ @@System$//

I used the same for Removed :%s/Removed //

Try this way:

sudo dnf history undo 339

This also removes packages that depend on it.

Avoid using the -y option.

2 Likes

I think OP broke it when they did Ctrl+C

DNF handles history rollback and history undo differently, see:
dnf: DNF Command Reference | dnf System Administration | Man Pages | ManKier

2 Likes

Understanding system commands and how the package manger works is critical.
Dnf always provides the list of what it proposes to do (install or remove). It continues automatically when the -y option is passed, but waits for confirmation if it does not receive the -y. User error in many cases when using the -y option with dnf.

We can see the output of the command in (https://0x0.st/XoCL.txt) that 688 packages will be installed, but 4158 packages were removed as per

So, will this undo it to previous state or is it an incomplete operation?

DNF uses exact package versions as critical part of transaction, but Fedora repos store only the initial and latest package versions and discard intermediary ones, which makes undoing transactions problematic for packages that have been upgraded more than once.

I frequently update all dnf packages the last time it was around 5 to 7 days ago. Is it likely that so many packages got removed? So is it better to do what you suggested or to manually install each package as per previous commentor?

If you need help with the script please post. I’ll be here for a while today.