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