Преглед изворни кода

debian: Backup all databases with user percolated data

We want to backup all databases that have possible user data, in case
something went wrong, or one of the databases got lost or similar.
Guillem Jover пре 12 година
родитељ
комит
c531799acf
2 измењених фајлова са 26 додато и 5 уклоњено
  1. 1 0
      debian/changelog
  2. 25 5
      debian/dpkg.cron.daily

+ 1 - 0
debian/changelog

@@ -90,6 +90,7 @@ dpkg (1.17.7) UNRELEASED; urgency=low
     kept being supported to handle existing bzip2 compressed .deb files.
     kept being supported to handle existing bzip2 compressed .deb files.
   * Use GNU tar's --no-unquote when using -T in dpkg-deb to avoid mangling
   * Use GNU tar's --no-unquote when using -T in dpkg-deb to avoid mangling
     filenames. Reported by Niels Thykier <niels@thykier.net>. Closes: #743687
     filenames. Reported by Niels Thykier <niels@thykier.net>. Closes: #743687
+  * Backup all databases with user data, not just the status database.
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * German (Sven Joachim).
   * German (Sven Joachim).

+ 25 - 5
debian/dpkg.cron.daily

@@ -1,10 +1,30 @@
 #!/bin/sh
 #!/bin/sh
 
 
-# Backup the 7 last versions of dpkg's status file
+dbdir=/var/lib/dpkg
+
+# Backup the 7 last versions of dpkg databases containing user data.
 if cd /var/backups ; then
 if cd /var/backups ; then
-    if ! cmp -s dpkg.status.0 /var/lib/dpkg/status ; then
-            cp -p /var/lib/dpkg/status dpkg.status
-            savelog -c 7 dpkg.status >/dev/null
+    # We backup all relevant database files if any has changed, so that
+    # the rotation number always contains an internally consistent set.
+    dbchanged=no
+    dbfiles="arch status diversions statoverride"
+    for db in $dbfiles ; do
+        if ! cmp -s dpkg.${db}.0 $dbdir/$db ; then
+            dbchanged=yes
+            break;
+        fi
+    done
+    if [ "$dbchanged" = "yes" ] ; then
+        for db in $dbfiles ; do
+            cp -p $dbdir/$db dpkg.$db
+            savelog -c 7 dpkg.$db >/dev/null
+        done
     fi
     fi
-fi
 
 
+    # The alternatives database is independent from the dpkg database.
+    if ! test -e alternatives.tar.0 ||
+       ! tar -df alternatives.tar.0 -C $dbdir alternatives >/dev/null ; then
+        tar -cf alternatives.tar -C $dbdir alternatives
+        savelog -c 7 -J alternatives.tar >/dev/null
+    fi
+fi