dpkg.cron.daily 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. dbdir=/var/lib/dpkg
  3. # Backup the 7 last versions of dpkg databases containing user data.
  4. if cd /var/backups ; then
  5. # We backup all relevant database files if any has changed, so that
  6. # the rotation number always contains an internally consistent set.
  7. dbchanged=no
  8. dbfiles="arch status diversions statoverride"
  9. for db in $dbfiles ; do
  10. if ! cmp -s dpkg.${db}.0 $dbdir/$db ; then
  11. dbchanged=yes
  12. break;
  13. fi
  14. done
  15. if [ "$dbchanged" = "yes" ] ; then
  16. for db in $dbfiles ; do
  17. [ -e $dbdir/$db ] || continue
  18. cp -p $dbdir/$db dpkg.$db
  19. savelog -c 7 dpkg.$db >/dev/null
  20. done
  21. fi
  22. # The alternatives database is independent from the dpkg database.
  23. dbalt=alternatives
  24. # Switch the alternatives database backups from xz to gzip, as the latter
  25. # is Essential and we can rely on it being always present, using xz here
  26. # is not worth the trouble, disk space savings, or possible additional
  27. # dependencies.
  28. for dbseq in `seq 1 6` ; do
  29. dbfile=${dbalt}.tar.${dbseq}
  30. [ -e "${dbfile}.xz" ] || continue
  31. unxz ${dbfile}.xz
  32. gzip -9 $dbfile
  33. done
  34. # XXX: Ideally we'd use --warning=none instead of discarding stderr, but
  35. # as of GNU tar 1.27.1, it does not seem to work reliably (see #749307).
  36. if ! test -e ${dbalt}.tar.0 ||
  37. ! tar -df ${dbalt}.tar.0 -C $dbdir $dbalt >/dev/null 2>&1 ;
  38. then
  39. tar -cf ${dbalt}.tar -C $dbdir $dbalt >/dev/null 2>&1
  40. savelog -c 7 ${dbalt}.tar >/dev/null
  41. fi
  42. fi