Downgrading all Debian packages to a specific date

Vincent Bernat

Un­like NixOS, De­bian does not have a built-in mech­a­nism to roll back an in­stal­la­tion to a spe­cific point in time. How­ever, thanks to snapshot.debian.org, a way­back ma­chine for De­bian pack­ages, it is pos­si­ble to down­grade all pack­ages to the ver­sions from a cho­sen date.

Let’s sup­pose we want to go back to Jan­u­ary 20th, 2020. In /etc/​apt/​sources.​list.​d/snapshot.​list, we add a date-spe­cific snap­shot 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 pri­or­ity of all pack­ages from this source to 1001. This is above the de­fault pri­or­ity of 500 and over 1000 to al­low down­grade. See apt_​preferences(5) man­ual page for more details.

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

Af­ter run­ning apt update, we can check the re­sult 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 re­quest­ing an up­grade, we will ef­fec­tively be pro­posed to down­grade ev­ery­thing to the ver­sions 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]