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.

Purpose

  • Reinstall your custom toolset after a clean Debian installation.
  • Clone the package environment to another machine.
  • Keep a minimal and reproducible system profile.

Backup Procedure

Run the backup script to generate an updated list:

apt-mark showmanual > /etc/apt/packages.list

This will save only the packages that were manually installed (not automatically installed dependencies).

Restoring Packages

To restore your manually installed packages on a new system:

  1. Ensure APT sources are configured under /etc/apt/sources.list.
  2. Place packages.list into /etc/apt/.
  3. Update package lists:

    apt update
  4. Install all packages from the list:

    xargs -a /etc/apt/packages.list apt install -y
  5. Optionally remove unneeded packages:

    apt autoremove

System Cloning Use Case

This file can be used as a lightweight system cloning tool.
By applying the same packages.list on multiple systems, you replicate your exact software environment without needing a full system image.

Notes

  • The list is intentionally minimal.
  • Dependencies are not included.
  • Useful for reproducible setups or quick workstation rebuilds.

vim /etc/cron.daily/pkg-list

#!/bin/sh
# Script Version: 01
# Description: Backup manually installed apt packages to /etc/apt/packages.list

# Reinstall all saved manual packages:
# xargs -a /etc/apt/packages.list apt install -y

LIST_FILE=/etc/apt/packages.list
apt-mark showmanual > $LIST_FILE
# echo "[DEBUG] Backup written to $LIST_FILE"