logger = logger_init()
-def keep_liveboot(name):
+def liveboot_to_keep(name):
con = db_connect()
cur = con.cursor()
try:
- cur.execute("SELECT keep_image FROM liveboot WHERE build_name = '%s'" % (name))
+ cur.execute("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
except psycopg2.DatabaseError as e:
logger.debug("SELECT keep_image FROM liveboot WHERE build_name = '%s' and keep_image = true" % (name))
return False
if cur.fetchone():
return True
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print("usage: %s $liveboot_name")
+ sys.exit(1)
+ name = sys.argv[1]
+ if not liveboot_to_keep(name):
+ sys.exit(1)
# copyright 2012 Holger Levsen <holger@layer-acht.org>
# GPL2 licenced
-set -x
-export
+#set -x
+#export
-# some settings
+# no configuration below this block
AMOUNT_TO_KEEP=15
-KEPT=0
+LIVEBOOT_IMAGE_PATH="/srv/mirror/liveboot"
-for DIRECTORY in $(ls -1r) ; do
- echo -n $DIRECTORY
- if ! ./keep_liveboot.py "$DIRECTORY" && [ $KEPT -le $AMOUNT_TO_KEEP ] ; then
- echo we can delete this one
- else
- echo keep it
+echo
+echo "liveboot garbage collection"
+echo "---------------------------"
+echo "- first goes through all liveboot images and keeps those with the 'keep'-flag set"
+echo "- second, it will go through all liveboot images (started with the latest) and keeps images until $AMOUNT_TO_KEEP liveboot images are kept. All the others will be deleted."
+echo
+
+KEPT=0
+FIRST_PASS=$(ls -1r $LIVEBOOT_IMAGE_PATH)
+SECOND_PASS=""
+for DIRECTORY in $FIRST_PASS ; do
+ if ./keep_liveboot.py "$DIRECTORY" ; then
+ echo -n "$DIRECTORY: "
+ echo keep flag set, keeping it.
+ else
+ SECOND_PASS="$SECOND_PASS $DIRECTORY"
+ fi
+done
+for DIRECTORY in $SECOND_PASS ; do
+ echo -n "$DIRECTORY: "
+ if [ $KEPT -le $AMOUNT_TO_KEEP ] ; then
+ echo keep it, there is enough space left...
let "KEPT=KEPT+1"
+ else
+ echo "deleted."
+ echo rm -rf "$LIVEBOOT_IMAGE_PATH/$DIRECTORY"
+ echo FIXME: still need to remove the liveboot from cidb...
fi
done
+echo
+echo
+
+echo "Existing liveboot images after garbage collection:"
+ls -1r $LIVEBOOT_IMAGE_PATH
+echo
+echo "Free diskspace on sagunt:"
+df -h $LIVEBOOT_IMAGE_PATH
+echo "The liveboot images are copied to other servers which might not have as much space available."