#!/bin/sh # backuppc only has global pruning of backups # to remove with a finer granularity, we need to do work here # the nightly cleanup then tidies up the pool # (NB: this could take $Conf{BackupPCNightlyPeriod} days - see config.pl) # paranoia - unless you specify "-f", nothing will happen! DEBUG="echo NOACTION: " if [ "$1" = "-f" ]; then DEBUG="" fi backuppc_base=/var/lib/backuppc/pc die() { echo "$@" >&2 exit 1 } # prunes old files # first argument is which hosts to prune (or '*') # second argument is files/directories to delete prune() { if [ "$#" -lt 2 ]; then echo "Invalid arguments($@) to prune()" >&2 return 1 fi days="$1" hosts="$2" # ensure leading slash but no trailing slash glob="/${3#/}" glob="${glob%/}" glob=`echo "$glob" | sed 's/\//\/f/g; s/^/f%2f/;'` cd $backuppc_base || die "Unable to cd \"$backuppc_base\"" find $hosts -maxdepth 1 -type d -mtime +$days -exec $DEBUG rm -rf {}/$glob \; } # logs prune 10 '*' /var/log/ # osiris prune 3 '*' /var/lib/osirismd/hosts