From 19d766449eb7ad36602042318f20e77a50d80c94 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Nov 22 2019 12:43:46 +0000 Subject: filesystem pruning cronjobs --- diff --git a/README.md b/README.md index c570ec9..6e68947 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ Supplementary tools and utilities for the Koji build system * `koji-list-built-with` - List all the builds that had a given build in the buildroot. +* `koji-prune-scratch` - Sample cronjob for cleaning scratch build data + +* `koji-prune-work` - Sample cronjob for cleaning work directories + * `koji-remove-arch` - Globally remove an architecture from all tags in Koji. diff --git a/src/bin/koji-prune-scratch b/src/bin/koji-prune-scratch new file mode 100755 index 0000000..ee642dc --- /dev/null +++ b/src/bin/koji-prune-scratch @@ -0,0 +1,21 @@ +#!/bin/bash +# remove old scratch builds + +TOPDIR=/mnt/koji + +cd $TOPDIR/scratch/ + +# we completely remove those that are old enough +# scratch directories are /mnt/koji/scratch/$username/task_$taskid/ +# note that $username might contain a slash (e.g. host principals) +find $TOPDIR/scratch/ -mindepth 2 -type d -name 'task_*' -prune -mtime +21 -exec rm -rf {} \; + +# For content besides srpms/logs/poms we prune much more aggressively +# note that this step normally alters the mtime of the task dir, effectively +# adding to the above retention window. +for taskdir in $(find $TOPDIR/scratch/ -mindepth 2 -type d -name 'task_*' -prune -mtime +7) +do + find "$taskdir" -type f \! -name '*.src.rpm' \! -name '*.log' \! -name '*.pom' -delete +done + +find $TOPDIR/scratch/ -maxdepth 1 -type d -mtime +1 -empty -delete diff --git a/src/bin/koji-prune-work b/src/bin/koji-prune-work new file mode 100755 index 0000000..0dfdb50 --- /dev/null +++ b/src/bin/koji-prune-work @@ -0,0 +1,19 @@ +#!/bin/bash + +# remove old stuff under kojiroot/work + +TOPDIR=/mnt/koji +TIMEARG="-mtime +2" + +# for tasks, try to remove as a unit +for x in $(find "$TOPDIR"/work/tasks/ -mindepth 2 -maxdepth 2 -type d $TIMEARG); do + find "$x" -xdev '!' -type d -print0 | xargs -0 -r rm -f + find "$x" -xdev -depth -type d -print0 | xargs -0 -r rmdir +done + +# for anything else, just remove old stuff +# but don't remove the top level dirs (e.g. cli-build) +for x in $(find "$TOPDIR"/work -maxdepth 1 -mindepth 1 \! -name tasks); do + find "$x" -xdev '!' -type d $TIMEARG -print0 | xargs -0 -r rm -f + find "$x" -xdev -depth -mindepth 1 -type d -empty -print0 | xargs -0 -r rmdir +done