#!/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 # # only affect files with the status in the list status= # phases # -cC remove command history by date remove_command_history= # -dD remove dry run remove_dry_run=1 # -eE remove orphaned elf remove_orphaned_elf=1 # -fF remove failed remove_failed=1 # -hH fix file content hash fix_hash=0 # -hH remove install history by date remove_history= # -lL remove old logs, given by date remove_logs= # -nN remove acked notes remove_acked_notes=0 # -oO remove outdated packages, unless preserved remove_old_packages=0 # -pP remove history for missing packages clean_missing_package_history=0 # -rR remove orphaned rows in files table packagefiles, notes, scripts, ... remove_orphaned_files=1 # -hH remove all file content that is not scripts or configs remove_packagefile_content=1 remove_script_content=1 remove_config_content=1 # -rR remove removed packages, unless preserved remove_removed_packages=0 # -vV compactify the database file vacuum=1 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 # TODO use temporary gc delete log trigger? if [ $remove_incomplete_packages -ne 0 ]; then zpm shell $ZPMDB "delete from packages where hash is null" fi # remove old version packages, unless preserved # TODO need 'rstatus' flag if [ $remove_old_packages -ne 0 ]; then # TODO check for preserved # TODO add ability to keep a certain number of back packages zpm shell $ZPMDB "delete from packages where status = 'updated'" fi # remove removed packages, unless preserved # remove orphaned rows in files table # references in packagefiles, notes, scripts, possibly others if [ $remove_orphaned_files -ne 0 ]; then zpm shell $ZPMDB 'delete from files where hash in (select hash from filerefs where refcount = 0);' fi # remove old logs, given by date # remove acked notes if [ $remove_acked_notes -ne 0 ]; then zpm shell $ZPMDB 'delete from notes where ack != 0' fi # remove install history by date # remove history for missing packages if [ $clean_missing_package_history -ne 0 ]; then fi # remove command history by date if [ $vacuum -ne 0 ]; then # 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 fi