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 ##
How can get back everything to previous state?
After getting the previous state, is it possible to just remove lua from dnf?
How could one know what all other packages will be removed before removing the command? dnf info lua didn’t warn me of this!
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!
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.
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
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.
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?