From 652eaf995074da9af5b6bf3dae36d90b02c44f31 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Wed, 6 Nov 2019 15:53:27 +0100 Subject: [PATCH] Added max number of days to keep dumps. Improved launch script to retrieve relevant secrets, based on hostname and instance name. --- nettoyer_quotas.sh | 31 ++++++++++++++++++------------- start_or_update.sh | 6 ++++-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/nettoyer_quotas.sh b/nettoyer_quotas.sh index 3eba79e..c0d2ee2 100755 --- a/nettoyer_quotas.sh +++ b/nettoyer_quotas.sh @@ -1,34 +1,39 @@ #!/bin/bash #find /mnt/dumps -mtime +30 -print -# ce scrip efface les vieux dumps de la base de données. +# This script removes old database dumps. PURGEPATH=/mnt/dumps cd $PURGEPATH OLD_IFS="$IFS" +# We want to keep 5 Go free (unit: kB) +minfree=5000000 +# We want to keep 30 dumps max (min is 2) +maxkeep=30 + +count=$(ls | wc -l) +count_removed=0 + IFS=$(echo -en "\n\b") for file in `ls -rt` do IFS="$OLD_IFS" - # en Ko - espace_libre=`df -P "$PURGEPATH" | grep "$PURGEPATH" | head -n 1 | awk 'BEGIN{FS=" "} {print $4}'` - # We want to keep 5 Go free - if [ "$espace_libre" -lt 5000000 ] + # unit: KB + free_space=`df -P "$PURGEPATH" | grep "$PURGEPATH" | head -n 1 | awk 'BEGIN{FS=" "} {print $4}'` + if [ $(( $count - $count_removed )) -gt $(( $maxkeep - 2 )) ] then rm -rf -- "$file" && echo "Removed $file" + count_removed=$(( $count_removed + 1 )) + elif [ "$free_space" -lt $minfree ] + then + rm -rf -- "$file" && echo "Removed $file" + count_removed=$(( $count_removed + 1 )) else echo "Enough free space retrieved" break fi - # etc - # il faut faire attention, la valeur de l'IFS n'étant pas celle par défaut, certaines choses - # ne fonctionneront pas si tu fais des choses compliquées dans ta boucle, tu seras probablement - # obligé de restaurer/effacer la valeur d'IFS à chaque itération. sleep 1 IFS=$(echo -en "\n\b") done -echo "$espace_libre Ko free on $PURGEPATH" +echo "$free_space KB free on $PURGEPATH" IFS="$OLD_IFS" - -#suite du script - diff --git a/start_or_update.sh b/start_or_update.sh index 1b15bf2..98e6159 100755 --- a/start_or_update.sh +++ b/start_or_update.sh @@ -1,6 +1,8 @@ #!/bin/bash -test -f ~/secrets.tar.gz.enc || curl -o ~/secrets.tar.gz.enc https://cloud.scimetis.net/s/$KEY/download -openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc | tar -zxv --strip 2 secrets/docker-mysql-stack/crontab secrets/docker-mysql-stack/debian.cnf +test -z $1 || HOST="_$1" +test -z $2 || INSTANCE="_$2" +test -f ~/secrets.tar.gz.enc || curl -o ~/secrets.tar.gz.enc "https://cloud.scimetis.net/s/${KEY}/download?path=%2F&files=secrets.tar.gz.enc" +openssl enc -aes-256-cbc -d -in ~/secrets.tar.gz.enc | tar -zxv --strip 2 secrets/docker-mysql-stack${HOST}${INSTANCE}/crontab secrets/docker-mysql-stack${HOST}${INSTANCE}/debian.cnf sudo chown root. crontab debian.cnf sudo chmod 644 crontab # --force-recreate is used to recreate container when crontab file has changed