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:
parent
3d358a88c2
commit
652eaf9950
@ -1,34 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#find /mnt/dumps -mtime +30 -print
|
#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
|
PURGEPATH=/mnt/dumps
|
||||||
cd $PURGEPATH
|
cd $PURGEPATH
|
||||||
OLD_IFS="$IFS"
|
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")
|
IFS=$(echo -en "\n\b")
|
||||||
for file in `ls -rt`
|
for file in `ls -rt`
|
||||||
do
|
do
|
||||||
IFS="$OLD_IFS"
|
IFS="$OLD_IFS"
|
||||||
# en Ko
|
# unit: KB
|
||||||
espace_libre=`df -P "$PURGEPATH" | grep "$PURGEPATH" | head -n 1 | awk 'BEGIN{FS=" "} {print $4}'`
|
free_space=`df -P "$PURGEPATH" | grep "$PURGEPATH" | head -n 1 | awk 'BEGIN{FS=" "} {print $4}'`
|
||||||
# We want to keep 5 Go free
|
if [ $(( $count - $count_removed )) -gt $(( $maxkeep - 2 )) ]
|
||||||
if [ "$espace_libre" -lt 5000000 ]
|
|
||||||
then
|
then
|
||||||
rm -rf -- "$file" && echo "Removed $file"
|
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
|
else
|
||||||
echo "Enough free space retrieved"
|
echo "Enough free space retrieved"
|
||||||
break
|
break
|
||||||
fi
|
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
|
sleep 1
|
||||||
IFS=$(echo -en "\n\b")
|
IFS=$(echo -en "\n\b")
|
||||||
done
|
done
|
||||||
echo "$espace_libre Ko free on $PURGEPATH"
|
echo "$free_space KB free on $PURGEPATH"
|
||||||
|
|
||||||
IFS="$OLD_IFS"
|
IFS="$OLD_IFS"
|
||||||
|
|
||||||
#suite du script
|
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
test -f ~/secrets.tar.gz.enc || curl -o ~/secrets.tar.gz.enc https://cloud.scimetis.net/s/$KEY/download
|
test -z $1 || HOST="_$1"
|
||||||
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 $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 chown root. crontab debian.cnf
|
||||||
sudo chmod 644 crontab
|
sudo chmod 644 crontab
|
||||||
# --force-recreate is used to recreate container when crontab file has changed
|
# --force-recreate is used to recreate container when crontab file has changed
|
||||||
|
Loading…
Reference in New Issue
Block a user