diff --git a/schedule/extra/01_extract_hydra.xml b/schedule/extra/01_extract_hydra.xml new file mode 100644 index 0000000..188e951 --- /dev/null +++ b/schedule/extra/01_extract_hydra.xml @@ -0,0 +1,20 @@ + + + + + + + daily + + + + + + + non + dbEnableBackup + none + daily + + + diff --git a/schedule/scripts/extract_hydra_logs b/schedule/scripts/extract_hydra_logs new file mode 100644 index 0000000..f5be79b --- /dev/null +++ b/schedule/scripts/extract_hydra_logs @@ -0,0 +1,69 @@ +#!/bin/bash + +DESC="Extraction des logs de connexion de la base Hydra" + +. /usr/share/eole/schedule/config.sh + +file_date=$(date '+%Y%m%d' -d@$(($(date +%s) -3600*24))) # Date pour le format des noms de fichier +today=$(date '+%Y-%m-%d') # Date de fin de requête +yesterday=$(date '+%Y-%m-%d' -d@$(($(date +%s) -3600*24))) # Date de début de requête +exit_status=0 + +echo "Begin date: $(date)" + +mysql --defaults-file=/etc/mysql/debian.cnf hydra <= '${yesterday} 00:00:00' and requested_at < '${today} 00:00:00' + order by requested_at ; +EOF +(( exit_status = exit_status || $? )) + +mysql --defaults-file=/etc/mysql/debian.cnf hydra <= '${yesterday} 00:00:00' and requested_at < '${today} 00:00:00' + order by requested_at ; +EOF +(( exit_status = exit_status || $? )) + +mysql --defaults-file=/etc/mysql/debian.cnf hydra <= '${yesterday} 00:00:00' and requested_at < '${today} 00:00:00' + order by requested_at ; +EOF +(( exit_status = exit_status || $? )) + +# Tags must be 32 char long max (otherwise, default fwd template truncates it) +logger -f /var/lib/mysql/hydra/access-${file_date} -t mariadb_hydra-access-${file_date} +logger -f /var/lib/mysql/hydra/consent-request-handled-${file_date} -t mariadb_hydra-consreq-h-${file_date} +logger -f /var/lib/mysql/hydra/authentication-request-${file_date} -t mariadb_hydra-authreq-${file_date} + +# Remove log files older than 7 days (already saved on the NAS) +find /var/lib/mysql/hydra/ -name 'access-*' -type f -mtime +7 -exec rm -vf {} \; +find /var/lib/mysql/hydra/ -name 'consent-request-handled-*' -type f -mtime +7 -exec rm -vf {} \; +find /var/lib/mysql/hydra/ -name 'authentication-request-*' -type f -mtime +7 -exec rm -vf {} \; + +find /var/log/rsyslog/local/mariadb_hydra/ -name 'access-*' -type f -mtime +7 -exec rm -vf {} \; +find /var/log/rsyslog/local/mariadb_hydra/ -name 'consreq-h-*' -type f -mtime +7 -exec rm -vf {} \; +find /var/log/rsyslog/local/mariadb_hydra/ -name 'authreq-*' -type f -mtime +7 -exec rm -vf {} \; + +echo "End date: $(date)" + +exit $exit_status diff --git a/schedule/scripts/mariadb b/schedule/scripts/mariadb index feb407e..7a83ea4 100644 --- a/schedule/scripts/mariadb +++ b/schedule/scripts/mariadb @@ -9,19 +9,11 @@ DESC="Exportation des bases MariaDB" MYSQLSAVDIR=$SAVDIR/sql OPTION="--lock-tables" -rm -f $MYSQLSAVDIR/*.sql || true -mkdir -p $MYSQLSAVDIR +if [[ -d ${MYSQLSAVDIR} ]] +then + rm -rf ${MYSQLSAVDIR} + mkdir -p ${MYSQLSAVDIR} +fi -DATABASES=$(mysql --defaults-file=/etc/mysql/debian.cnf -e 'show databases' | grep -v '^Database$') -for databasename in $DATABASES; do - case "$databasename" in - information_schema|performance_schema|bareos) - continue - ;; - *) - mysqldump --defaults-file=/etc/mysql/debian.cnf --databases $databasename --flush-privileges --create-options -Q -c $OPTION > $MYSQLSAVDIR/$databasename.sql - ;; - esac -done - -exit 0 +mariabackup --defaults-file=/etc/mysql/debian.cnf --backup --target-dir=$MYSQLSAVDIR +exit $? diff --git a/scripts/get_hydra_table_sizes b/scripts/get_hydra_table_sizes new file mode 100755 index 0000000..3887e84 --- /dev/null +++ b/scripts/get_hydra_table_sizes @@ -0,0 +1,25 @@ +#!/bin/bash + +( +mysql --defaults-file=/etc/mysql/debian.cnf hydra <