]> pd.if.org Git - zpackage/blob - zpm-gc
remove debug
[zpackage] / zpm-gc
1 #!/bin/sh
2
3 # garbage collect a package database
4 # flags to skip phases
5
6 # -C clear all phases
7 # -n dry run
8 # -a all phases
9 # default is failed packages, orphaned elf, vacuum
10
11 # phases
12 # -cC remove command history by date
13 # -dD remove dry run
14 # -eE remove orphaned elf
15 # -fF remove failed
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
26
27 db=${1:-${ZPMDB:-/var/lib/zpm/local.db}}
28
29 if [ -z "$db" ]; then
30         echo must specify database file
31         exit 1
32 fi
33
34 ZPMDB=$db
35 export ZPMDB
36
37 # check for incorrect hash file content
38
39 # remove orphaned elf info
40
41 # remove failed packages
42 for pkg in $(zpm list -s failed); do
43         zpm log -i -a 'gc removing' -t "$pkg"
44         zpm rmpackage "$pkg"
45 done
46
47 for pkg in $(zpm list -s dryrun); do
48         zpm log -i -a 'gc removing' -t "$pkg"
49         zpm rmpackage "$pkg"
50 done
51
52 # remove incomplete packages
53
54 # remove outdated packages, unless preserved
55 # TODO need 'rstatus' flag
56
57 # remove removed packages, unless preserved
58
59 # remove orphaned rows in files table
60 # references in packagefiles, notes, scripts, possibly others
61
62 zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);'
63
64 # remove old logs, given by date
65
66 # remove acked notes
67
68 # remove install history by date
69
70 # remove history for removed packages
71
72 # remove command history by date
73
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)
79
80 printf 'original size %s\n' $osize
81 printf 'new size %s\n' $nsize