Added max number of days to keep dumps. Improved launch script to retrieve relevant secrets, based on hostname and instance name.

This commit is contained in:
yohan 2019-11-06 15:53:27 +01:00
parent 3d358a88c2
commit 652eaf9950
2 changed files with 22 additions and 15 deletions

View File

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

View File

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