#!/bin/sh # garbage collect a package database # flags to skip phases # -C clear all phases # -n dry run # -a all phases # default is failed packages, orphaned elf, vacuum # # phases # -cC remove command history by date # -dD remove dry run # -eE remove orphaned elf # -fF remove failed # -hH fix file content hash # -hH remove install history by date # -lL remove old logs, given by date # -nN remove acked notes # -oO remove outdated packages, unless preserved # -pP remove history for removed packages # -rR remove orphaned rows in files table packagefiles, notes, scripts, ... # -rR remove removed packages, unless preserved # -vV compactify the database file db=${1:-${ZPMDB:-/var/lib/zpm/local.db}} if [ -z "$db" ]; then echo must specify database file exit 1 fi ZPMDB=$db export ZPMDB # check for incorrect hash file content # remove orphaned elf info # remove failed packages for pkg in $(zpm list -s failed); do zpm log -i -a 'gc removing' -t "$pkg" zpm rmpackage "$pkg" done for pkg in $(zpm list -s dryrun); do zpm log -i -a 'gc removing' -t "$pkg" zpm rmpackage "$pkg" done # remove incomplete packages # remove outdated packages, unless preserved # TODO need 'rstatus' flag # remove removed packages, unless preserved # remove orphaned rows in files table # references in packagefiles, notes, scripts, possibly others zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);' # remove old logs, given by date # remove acked notes # remove install history by date # remove history for removed packages # remove command history by date # compactify the database file osize=$(zpm stat -f '%s' $ZPMDB) zpm log -v -i -a 'gc compacting' -t $ZPMDB zpm shell $ZPMDB vacuum nsize=$(zpm stat -f '%s' $ZPMDB) printf 'original size %s\n' $osize printf 'new size %s\n' $nsize