Downgrading all Debian packages to a specific date

Vincent Bernat

Unlike NixOS, Debian doesn’t have a builtin mechanism to rollback an installation to a specific point in time. However, thanks to snapshot.debian.org, a wayback machine for Debian packages, it is possible to downgrade all packages to the versions from a chosen date.

Let’s suppose we want to go back to January, 20th 2020. In /etc/apt/sources.list.d/snapshot.list, we add a date-specific snapshot as a source:

deb [check-valid-until=no] https://snapshot.debian.org/archive/debian/20200120T111800Z/ unstable main contrib non-free

In /etc/apt/preferences.d/snapshot.pref, we set the priority of all packages from this source to 1001. This is above the default priority of 500 and over 1000 to allow downgrade. See apt_preferences(5) manual page for more details.

Package: *
Pin: origin snapshot.debian.org
Pin-Priority: 1001

After running apt update, we can check the result with apt policy:

$ apt policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
1001 https://snapshot.debian.org/archive/debian/20200120T111800Z unstable/non-free amd64 Packages
     release o=Debian,a=unstable,n=sid,l=Debian,c=non-free,b=amd64
     origin snapshot.debian.org
1001 https://snapshot.debian.org/archive/debian/20200120T111800Z unstable/contrib amd64 Packages
     release o=Debian,a=unstable,n=sid,l=Debian,c=contrib,b=amd64
     origin snapshot.debian.org
1001 https://snapshot.debian.org/archive/debian/20200120T111800Z unstable/main amd64 Packages
     release o=Debian,a=unstable,n=sid,l=Debian,c=main,b=amd64
     origin snapshot.debian.org
[…]

When requesting an upgrade, we will effectively be proposed to downgrade everything to the versions in the snapshot:

$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  libdns-export1104 libgspell-1-1 libiptc0 libisc-export1100
The following packages will be DOWNGRADED:
  bash-completion bear binutils binutils-common binutils-dev binutils-doc
  binutils-x86-64-linux-gnu bison blackbird-gtk-theme blender blender-data
  clang-6.0 clang-7 clang-8 clang-tools-8 cpp-9 cppcheck cpuid cups
  […]
0 upgraded, 4 newly installed, 451 downgraded, 0 to remove and 0 not upgraded.
Need to get 1,053 MB/1,060 MB of archives.
After this operation, 9,282 kB disk space will be freed.
Do you want to continue? [Y/n]