Backup and restore all your packages on Debian based machines.

So, you’re somebody that plays a lot with Linux?
Create a script that runs weekly or so with the commands below, and you’ll always be prepared for the worst that life can toss your direction!
Okay, that might be overly optimistic, but it can’t hurt, and can save you a ton of time when you rebuild a machine.


#!/bin/bash
# SRJ 2008-09-03
mkdir SourcesAndPackages
cd SourcesAndPackages
dpkg --get-selections | grep -v deinstall > InstalledPackages.txt
cp -a /etc/apt .
# Comment out the lines above and uncomment the lines below to restore.
# cd SourcesAndPackages
# sudo cp -a apt /etc/
# sudo apt-get update
# sudo apt-get dist-upgrade
# sudo dpkg --set-selections < InstalledPackages.txt # sudo apt-get dselect-upgrade