From 1509ed9d36af59b2f1eeff7c04e6ef1ca7d2d9d2 Mon Sep 17 00:00:00 2001 From: lkiesow Date: Mon, 2 Sep 2024 05:16:40 +0000 Subject: [PATCH] Cleanup and delete old deployments --- cleanup-deployments.sh.51 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cleanup-deployments.sh.51 diff --git a/cleanup-deployments.sh.51 b/cleanup-deployments.sh.51 new file mode 100644 index 00000000..372a768b --- /dev/null +++ b/cleanup-deployments.sh.51 @@ -0,0 +1,18 @@ +#!/bin/bash + + + +# That is list the files of type directory whose name does not contain +# a non-digit. So we only process automated deployments. +# +# Without LC_ALL=C, some find implementations, including GNU find could +# also list files whose name contains sequences of bytes that don't form +# valid characters in the current locale (like a répertoire encoded in +# iso8859-1 (mkdir $'r\xe9pertoire') in a locale that uses UTF-8 as charset). +DEPLOYMENTS=$(LC_ALL=C find . -maxdepth 1 ! -name '*[!0-9]*' -type d -printf '%p\n') + + +for instance in $DEPLOYMENTS +do + find "$instance" -maxdepth 1 -mindepth 1 -type d -printf '%p\n' | sort -g | head -n -3 | xargs rm -rf +done