Initial commit.
This commit is contained in:
commit
c955d5deca
17
README
Normal file
17
README
Normal file
@ -0,0 +1,17 @@
|
||||
Why ?
|
||||
pour centraliser la sauvegarde et l'administration des BDD
|
||||
|
||||
Si première utilisation :
|
||||
|
||||
docker network create mysqlnet
|
||||
docker volume create --name mysql-server_data
|
||||
docker volume create --name mysql-server_dumps
|
||||
rsync -itrlpgovDHXP var_lib_mysql/* /var/lib/docker-latest/volumes/mysql-server_data/_data/
|
||||
chcon -Rt svirt_sandbox_file_t /var/lib/docker-latest/volumes/mysql-server_data/_data/
|
||||
chcon -Rt svirt_sandbox_file_t /var/lib/docker-latest/volumes/mysql-server_dumps/_data/
|
||||
|
||||
Utilisation :
|
||||
|
||||
Les droits des fichiers doivent être corrigés avant de lancer la stack avec docker-compose up -d :
|
||||
chcon -u system_u -r object_r -t svirt_sandbox_file_t crontab
|
||||
chcon -u system_u -r object_r -t svirt_sandbox_file_t nettoyer_quotas.sh
|
13
crontab-example
Normal file
13
crontab-example
Normal file
@ -0,0 +1,13 @@
|
||||
# /etc/crontab: system-wide crontab
|
||||
# Unlike any other crontab you don't have to run the `crontab'
|
||||
# command to install the new version when you edit this file
|
||||
# and files in /etc/cron.d. These files also have username fields,
|
||||
# that none of the other crontabs do.
|
||||
|
||||
SHELL=/bin/sh
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
# m | h | day of month | month | day of week | user | command
|
||||
3 0 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server /root/nettoyer_quotas.sh > /proc/1/fd/2 2>&1
|
||||
3 1 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server sh -c "mysqldump --databases mysql -uroot -pXXXXXXXX > /mnt/dumps/mysql_dump-mysql_`date +\%d-\%m-\%Y`" > /proc/1/fd/2 2>&1
|
||||
13 1 * * * root docker -H tcp://127.0.0.1:2375 exec mysql-server sh -c "mysqldump --databases gogs owncloud semanticscuttle -uroot -pXXXXXXXX > /mnt/dumps/mysql_dump_`date +\%d-\%m-\%Y`" > /proc/1/fd/2 2>&1
|
35
docker-compose.yml
Normal file
35
docker-compose.yml
Normal file
@ -0,0 +1,35 @@
|
||||
version: "2.1"
|
||||
|
||||
services:
|
||||
|
||||
mysql-server:
|
||||
image: mysql-server
|
||||
container_name: mysql-server
|
||||
restart: always
|
||||
networks:
|
||||
- mysqlnet
|
||||
volumes:
|
||||
- mysql-server_data:/var/lib/mysql:Z
|
||||
- mysql-server_dumps:/mnt/dumps:Z
|
||||
- ./nettoyer_quotas.sh:/root/nettoyer_quotas.sh:Z
|
||||
|
||||
cron:
|
||||
image: cron
|
||||
restart: always
|
||||
network_mode: "host"
|
||||
volumes:
|
||||
- ./crontab:/etc/crontab:Z
|
||||
|
||||
networks:
|
||||
|
||||
mysqlnet:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
|
||||
mysql-server_data:
|
||||
external: true
|
||||
|
||||
mysql-server_dumps:
|
||||
external: true
|
||||
|
34
nettoyer_quotas.sh
Executable file
34
nettoyer_quotas.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
#find /mnt/dumps -mtime +30 -print
|
||||
# ce scrip efface les vieux dumps de la base de données.
|
||||
PURGEPATH=/mnt/dumps
|
||||
cd $PURGEPATH
|
||||
OLD_IFS="$IFS"
|
||||
|
||||
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 ]
|
||||
then
|
||||
rm -rf -- "$file" && echo "Removed $file"
|
||||
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"
|
||||
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
#suite du script
|
||||
|
Loading…
Reference in New Issue
Block a user