[patch] snapshot data auto-aging

Frank Ch. Eigler fche@elastic.org
Sun Aug 9 16:00:38 GMT 2026


commit bff35775eece0a1fbb224938f7654e97aa760cc3 (HEAD -> main)
gpg: Signature made Sun 09 Aug 2026 12:00:02 PM EDT
gpg:                using EDDSA key C60CFE9F27405101D06DE3B86D8D01ADE253B252
gpg: Good signature from "Frank Ch. Eigler <fche@sourceware.org>" [ultimate]
gpg:                 aka "Frank Ch. Eigler <fche@elastic.org>" [ultimate]
Primary key fingerprint: C60C FE9F 2740 5101 D06D  E3B8 6D8D 01AD E253 B252
Author: Frank Ch. Eigler <fche@redhat.com>
Date:   Sun Aug 9 11:59:35 2026 -0400

    publish-snapshots: age out old snapshots automatically
    
    Remove dated snapshot directories older than a project-specific
    retention period after each publish. gcc snapshots are kept for 30
    days (they are huge); all other projects are kept for 365 days. Age is
    determined from the epoch embedded in the dated directory name, since
    parent directory mtimes are touched during publishing.

diff --git a/publish-snapshots.sh b/publish-snapshots.sh
index 8a73742a2543..fe9e22541746 100644
--- a/publish-snapshots.sh
+++ b/publish-snapshots.sh
@@ -21,6 +21,39 @@ LOCKFILE=$HOME/publish_lock
 exec 200>$LOCKFILE
 flock -n 200 || exit 1
 
+# Age out old snapshots under $SNAPSHOTSDIR/$subdir.  The retention
+# period depends on the project (the first path component of the
+# subdir): gcc snapshots are huge, so keep them for a much shorter
+# time than the other projects.  Dated snapshot directories are named
+# YYYY-MM-DD_HH-MM_EPOCH, so we use the embedded epoch to decide age
+# rather than filesystem mtime (which is unreliable here because the
+# parent directories get touched).  The 'latest' symlink is skipped.
+age_snapshots() {
+    local subdir="$1"
+    local project="${subdir%%/*}"
+    local days=365
+    case "$project" in
+        gcc) days=30 ;;
+    esac
+    local now=$(date +%s)
+    local cutoff=$(( now - days*24*60*60 ))
+    local d name epoch
+    for d in "$SNAPSHOTSDIR/$subdir"/*; do
+        # Only consider real dated snapshot directories; skip the
+        # 'latest' symlink and any other non-directory entries.
+        [ -d "$d" ] && [ ! -L "$d" ] || continue
+        name=$(basename "$d")
+        epoch=${name##*_}
+        case "$epoch" in
+            ''|*[!0-9]*) continue ;;
+        esac
+        if [ "$epoch" -lt "$cutoff" ]; then
+            echo "Removing old snapshot $d (older than ${days} days)"
+            rm -rf "$d"
+        fi
+    done
+}
+
 if [ -f $PUBLISHDIR/$PUBLISHFILE ]; then
   # Make sure publishing dir is clean
   rm -rf $PUBLISHINGDIR
@@ -48,6 +81,9 @@ if [ -f $PUBLISHDIR/$PUBLISHFILE ]; then
     pdirs=$PUBLISHSUBDIR
     cd $SNAPSHOTSDIR
     while [ $pdirs != "." ]; do touch $pdirs; pdirs=$(dirname $pdirs); done
+
+    # Age out snapshots older than the retention period for this project
+    age_snapshots "$PUBLISHSUBDIR"
   else
     echo BAD subdir
   fi


More information about the Buildbot mailing list