Backing Up Fedora Packages
If you’re running a Fedora system, it’s wise to maintain backups of your installed packages. This makes system restoration much smoother in case of unforeseen hiccups. Below is a quick guide on how to achieve this.
Backing up
Backup using dnf:
- Command:
dnf list --installed > $HOME/dnf-installed.txt
- Note:
dnf
lacks a feature to filter dependencies automatically, so you’d have to sift through thednf-installed.txt
file to retain only necessary packages.
Backup using Flatpak:
- Command:
flatpak list > $HOME/flatpak-installed.txt
Store Your Backup List on a Private Gist
For those who might be hearing this term for the first time Gists are a neat feature provided by GitHub. They come in handy for storing code snippets, notes, and in our case, backup lists. Here’s how to push your backup to a private Gist:
-
SSH Setup:
- Ensure you have an SSH key associated with your GitHub account. If not, follow GitHub’s official guide.
-
Use GitHub’s CLI tool:
- Command for dnf:
cat $HOME/dnf-installed.txt | gh gist create -d "My dnf packages" -f dnf-installed.txt -p -
- Adjust the command for Flatpak, replacing filenames where necessary.
- Command for dnf:
-
Private Gist:
- Gists are public by default. Use the
--private
or-p
flag to ensure privacy. - Once your backup is pushed,
gh
provides a URL to your Gist. Bookmark or save it!
- Gists are public by default. Use the
Restoring Your Packages
Here’s how you can restore packages using the lists you’ve backed up:
Restore dnf packages:
- Extract package names, omitting version numbers.
- Use
sed
to extract names, thenxargs
to install viadnf
. - Sample script:
#!/bin/bash sed -E 's/([a-zA-Z\-]+).*/\1/' dnf-installed.txt | xargs sudo dnf install
- This script avoids using
-y
to let users verify the installation list.
- This script avoids using
Restore Flatpak apps:
- The following script reads from
stdin
, ensures Flatpak and its repositories are set up, and then installs apps:#!/bin/bash # Ensure Flatpak installation if ! command -v flatpak &>/dev/null; then echo "Flatpak not found. Installing Flatpak..." sudo dnf install flatpak fi # Add Flathub repository flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo # Install apps from stdin while IFS=$'\t' read -r app_name app_id app_version app_channel app_origin; do echo "Installing $app_name..." flatpak install --user flathub "$app_id" -y done echo "All apps installed successfully!"
- To use the above script:
cat flatpak-list.txt | ./install_apps.sh
Wrap Up
Maintaining and restoring Fedora packages is straightforward once you’re equipped with the right commands and scripts. The method described ensures a seamless backup on GitHub Gists and a hassle-free restoration process. Always remember to review your backups periodically to keep them current and relevant.
Stay safe, and keep your data backed up!