#32 filesystem pruning cronjobs
Merged 5 years ago by tkopecek. Opened 5 years ago by tkopecek.
tkopecek/koji-tools pruning  into  master

file modified
+4
@@ -36,6 +36,10 @@ 

  * `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.

  

@@ -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

@@ -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

I've two pruning script, which can be helpful to someone. It is a followup of https://pagure.io/koji/issue/1704

Commit 484b8d9 fixes this pull-request

Pull-Request has been merged by tkopecek

5 years ago

Pull-Request has been merged by tkopecek

5 years ago