Backup and Restore of Manually Installed APT Packages

This documentation describes how to save and restore manually installed APT packages on a Debian-based system.
It uses the apt-mark showmanual command to generate a clean list of user-installed packages, which can be used to restore or clone systems.

Overview

A list of manually installed packages is created and stored at:

/etc/apt/packages.list

This file is overwritten each time the backup tool is executed.

  1. cat /etc/apt/preferences; cat /etc/apt/preferences.d/*
  2. apt-cache policy
  3. ai apt-listchanges deborphan
for pkg in $(deborphan); do
   aptitude why "$pkg"
done
  1. apt remove --purge $(deborphan)
  2. apt list --installed
  3. apt-mark showhold
Tags
#!/bin/bash
# =============================================================================
# Script Name: lxc_package_install.sh
# Version: 1.1
# Author: Andreas Fleckl
# Description: This script installs a specified package in all running LXC
#              containers.

ai unattended-upgrades apt-utils

/etc/apt/apt.conf.d/50unattended-upgrades

  • "site=download.opensuse.org";
  • "site=deb.nodesource.com";
  • "site=download.jitsi.org";
  • "Docker:${distro_codename}";

 

backup

  1. dpkg --get-selections > dpkg.txt

restore

  1. dpkg --clear-selections
  2. dpkg --set-selections < dpkg.txt
  3. apt-get autoremove
  4. apt-get dselect-upgrade