Sunday, November 02, 2008

Ubuntu backup tip: save your package selections, including third-party, for later recovery

Today I wrote a little Python script which will pull a list of all of your installed packages, and then group them by Canonical-supplied, third-party PPA supplied, and manually installed .deb files.  This makes it a snap to automatically restore your package list if your system takes a dump, and even quickly put back your PPAs and manual debs as you go.

It requires python-twisted and python-apt installed.  Here is the script: dpkg-origins.

Recommended usage: Add this command to a script inside /etc/cron.daily:
  dpkg-origins | mail -s "Package selections for `hostname -s` as of `date`" yourname@youremail.com

When calamity strikes and you need to restore, you can pipe this file directly:

  cat selections.txt | sudo dpkg --set-selections && apt-get -u dselect-upgrade

This will begin installing all of the Canonical-supplied packages in selections.txt.  All other packages are commented out, but the file itself contains instructions for restoring your PPA's; then you uncomment some more packages and run the above again.  Finally, at the very top of the file, you will find a commented-out list of the packages (and versions) which were installed directly from a .deb file; manually download and install those.

No comments: