[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sync apt/dpkg state between systems?

Bob Proulx wrote:
> I should say a few more words about how to restore.

And there is always at least one more thing.

After restoring /etc that would include an update of
/etc/apt/sources.list which may be different if you had previously
installed backports or from other places.  Hopefully you didn't have
too complicated of a system.  After restoring /etc which included
sources.list then 'apt-get update'.

After having restored everything I would then compare the package
lists of packages that are now installed on the system with the list
of packages that were installed on the previous system.  They should
be pretty close.  They might not be completely identical.

You can get a list of packages installed at any of those snapshot
files in /var/backups with:

  $ grep-dctrl -s Package -n "install ok installed" /mnt/backup/var/backups/dpkg.status.0
  ...dumps a list of previously installed packages...

You can see what was different between the backup file and now.  Look
at the difference in package lists between the old system and the
current one.

  $ grep-dctrl -s Package -n "install ok installed" /var/backups/var/backups/dpkg.status.0 | sort > list.prev

  $ grep-status -s Package -n "install ok installed" | sort > list.now

  $ comm -3 list.prev list.now

That will show what is different between then and now.  React accordingly.

Hopefully the last thing I think of will be that you may have had
packages installed from backports.  If so then those won't currently
be installed from backports but from the standard repository.
Iceweasel is a good example.  I would normally use apt-show-versions
to tell me which packages are installed from backports.  But of course
that won't be ready on the new system yet.  So the best thing I can
think of at the moment is to generate a list of packages with "bpo" in
the version string and then manually recognize the top level package
and install it from backports.

  grep-dctrl -sPackage -n -FVersion bpo /mnt/backup/var/lib/dpkg/status | less

Then install those recognized top level packages from backports

  apt-get install -t squeeze-backports iceweasel ...

To compare packages with the version you can get the current list with:

  dpkg-query --show --showformat '${Package} ${Version}\n'

But this isn't so easy to get from the old status file.  I will use a
perl helper that reads paragraphs and prints the paragraph on one line.

  grep-dctrl -sPackage,Version -n -FStatus "install ok installed" /mnt/backup/var/lib/dpkg/status | perl -ln00e 'print(join(" ",split(" ",$_)))' | sort > list-ver.prev

  dpkg-query --show --showformat '${Package} ${Version}\n' > list-ver.cur

Then comparing those two files would show any differences in the
versions between before and now.

It would be possible to use the previously installed versions to
install by version.  (Such as apt-get install foo=1.2.3-4.)  But that
is both probably unnecessary and undesirable because if it recursed
down through all of the dependencies then packages that should be
installed automatically would then be marked as manually installed.
They would no longer be candidates for removal later with 'apt-get
autoremove'.  So personally because Debian is so easy to install using
'apt-get install ...' I would simply get mostly back to restored and
then just react as needed after that point.


Attachment: signature.asc
Description: Digital signature

Reply to: