1

In a LXC container I want be able to note the packages I've just updated to then recreate that situation any date after that.

I think I want to do something like:

dpkg-query --show | sed "s/\t/=/" > somewhere_safe.txt

That'd give a list like:

adduser=3.118
apache2=2.4.38-3+deb10u4
apache2-bin=2.4.38-3+deb10u4
apache2-data=2.4.38-3+deb10u4
apache2-utils=2.4.38-3+deb10u4
apparmor=2.13.2-10
apt=1.8.2.1
apt-listchanges=3.19
apt-transport-https=1.8.2.1
apt-utils=1.8.2.1
# and so on

Then post process that with an apt upgrade script that takes them all as arguments. Am I going about this the right way?

Rationale: apt update doesn't have an "as of this date" argument, meaning I couldn't recreate something if I wanted to, yet I generally speaking want something recreatable in respect of packages even if I'm not using docker-style image repositories.

paul_h
  • 121

1 Answers1

1
apt list --installed | sed s/Listing...// | awk -F "/" '{print $1}' >  $(date +aptlist-%m.%d.%Y-%H.%M.%S.txt)

Creates the file which lists all of the installed packages.

xargs -a ThatFileCratedAbove.txt sudo apt-get install

Will install them from the list

....I would test the file first with apt-get -s install to simulate installation, just to make sure the list is not going to cause any problems.. (though that might take a long time)

.
.
.

UPDATE FOR VERSION REQUIREMENT... If you wanted to capture the version and be able to install those versions later, then your apt list snapshot would need to be created like this instead of above:

apt list --installed | sed s/Listing...// | awk -F"[[:blank:]/]" '{ if( $1 ne '' ) print $1"="$3}' >  $(date +aptlist-%m.%d.%Y-%H.%M.%S.txt)
WU-TANG
  • 3,071
  • That creates a list like "adduser\n apache2-bin\n apache2-data\n apache2-utils\n apache2\n apparmor\n apt-listchanges\n apt-transport-https\n apt-utils\n apt\n attr" for me. There's no timestamp, hash or versionNum in there, so I'm not sure how I would update to anything other than "latest" if I ran it six months from now. – paul_h Oct 19 '20 at 13:41
  • the filename is the timestamp... But I see... you also want a version snapshot? – WU-TANG Oct 19 '20 at 13:50
  • yup, that's the idea – paul_h Oct 19 '20 at 14:14
  • then you were basically already there... as long as there were no additional header lines in your dpkg output. – WU-TANG Oct 19 '20 at 14:56
  • Close. If I take the somewhere_safe.txt list I had and xargs it into params for apt-get install as you have it it works great. One more test - I edit the list to change "adduser" from 3.118 to 3.116 and it barfs: E: Version '3.116' for 'adduser' was not found. It is possible that was never in the DebianBuster package list. I'll keep experimenting. – paul_h Oct 19 '20 at 15:42
  • that has nothing to do with the list.. that's apt telling you it just doesn't exist – WU-TANG Oct 19 '20 at 15:48
  • Yup https://askubuntu.com/questions/138284/how-to-downgrade-a-package-via-apt-get goes further. Find "no such a version" in page. My test is apt-cache showpkg cargo not showing any history of cargo before Debian 10.6. – paul_h Oct 19 '20 at 15:59
  • And https://unix.stackexchange.com/questions/79050/can-i-rollback-an-apt-get-upgrade-if-something-goes-wrong has a "It may no longer be in the repository" claim, which makes me think this is impossible via 'apt' today. – paul_h Oct 19 '20 at 16:06