Skip to content

Instantly share code, notes, and snippets.

@theKAKAN
Created December 6, 2018 14:13
Show Gist options
  • Save theKAKAN/69bfb34084802c4052880ca64413b3fd to your computer and use it in GitHub Desktop.
Save theKAKAN/69bfb34084802c4052880ca64413b3fd to your computer and use it in GitHub Desktop.
Backs up all the installed packages using pacman. Can be used to reinstall them later...
#!/bin/bash
# A script to back up all the program names.
# Can be used to install them again later on
TSTAMP=`date +%H:%M_%d-%m-%Y`
# Get all the programs available in the repos
# And paste them in a file
pacman -Qentq > ./native-packages_${TSTAMP}.txt
# Get all foreign packages
pacman -Qmq > ./foreign-packages_${TSTAMP}.txt
# To use it, download the file and execute it
# bash ./filename.sh
# To use the backed up files, use:
# pacman -S $(cat backup-file-name)
@theKAKAN
Copy link
Author

theKAKAN commented Dec 6, 2018

Direct command to do it all and create two files in your current directory:

wget -O - https://gist.github.com/theKAKAN/69bfb34084802c4052880ca64413b3fd/raw/3a7f590533fbf62d26784f5f7204db5cb5e193ab/backup-packages-name.sh -nv -q | sh

@theKAKAN
Copy link
Author

For DNF package manager. This should work well in Fedora and other RHEL distros with DNF installed

# Backup all DNF repos
dnf repoquery --qf '%{name}' --userinstalled \
| grep -v -- '-debuginfo$' \
| grep -v '^\(kernel-modules\|kernel\|kernel-core\|kernel-devel\)$' \
> "$(date) Packages.list"

@theKAKAN
Copy link
Author

For Flatpaks

flatpak list -a --columns=application \
| grep -v -- "Application ID$" \
> "$(date) flatpak Packages.list"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment