3 # garbage collect a package database
9 # default is failed packages, orphaned elf, vacuum
12 # -cC remove command history by date
14 # -eE remove orphaned elf
16 # -hH fix file content hash
17 # -hH remove install history by date
18 # -lL remove old logs, given by date
19 # -nN remove acked notes
20 # -oO remove outdated packages, unless preserved
21 # -pP remove history for removed packages
22 # -rR remove orphaned rows in files table packagefiles, notes, scripts, ...
23 # -hH remove all file content that is not scripts or configs
24 # -rR remove removed packages, unless preserved
25 # -vV compactify the database file
27 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
30 echo must specify database file
37 # check for incorrect hash file content
39 # remove orphaned elf info
41 # remove failed packages
42 for pkg in $(zpm list -s failed); do
43 zpm log -i -a 'gc removing' -t "$pkg"
47 for pkg in $(zpm list -s dryrun); do
48 zpm log -i -a 'gc removing' -t "$pkg"
52 # remove incomplete packages
54 # remove outdated packages, unless preserved
55 # TODO need 'rstatus' flag
57 # remove removed packages, unless preserved
59 # remove orphaned rows in files table
60 # references in packagefiles, notes, scripts, possibly others
62 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
64 # remove old logs, given by date
68 # remove install history by date
70 # remove history for removed packages
72 # remove command history by date
74 # compactify the database file
75 osize=$(zpm stat -f '%s' $ZPMDB)
76 zpm log -v -i -a 'gc compacting' -t $ZPMDB
77 zpm shell $ZPMDB vacuum
78 nsize=$(zpm stat -f '%s' $ZPMDB)
80 printf 'original size %s\n' $osize
81 printf 'new size %s\n' $nsize