Correction du script d'archivage des tables

tags/0.0.1 0.0.1
Daniel Berteaud 12 years ago
parent 0617e693c4
commit 1e845246d8
  1. 6
      root/etc/cron.monthly/samba-log-rotate

@ -3,7 +3,7 @@
DB_HOST=$(/sbin/e-smith/db configuration getprop samba-db-logd DbHost || echo localhost) DB_HOST=$(/sbin/e-smith/db configuration getprop samba-db-logd DbHost || echo localhost)
RETENTION=$(/sbin/e-smith/db configuration getprop samba-db-logd Retention || echo 365) RETENTION=$(/sbin/e-smith/db configuration getprop samba-db-logd Retention || echo 365)
SQL_DB=$(/sbin/e-smith/db configuration getprop samba-db-logd DbName) SQL_DB=$(/sbin/e-smith/db configuration getprop samba-db-logd DbName || echo 'samba_log')
TABNAME="audit" TABNAME="audit"
SQLCMD="mysql ${SQL_DB} --batch"; SQLCMD="mysql ${SQL_DB} --batch";
MONTH=$(date +%m) MONTH=$(date +%m)
@ -43,8 +43,8 @@ done
# Now check existing table to drop olds ones # Now check existing table to drop olds ones
for T in $(echo "show tables" | $SQLCMD | grep -v -P "^Tables_in_"$SQL_DB | grep -v -P "^audit$"); do for T in $(echo "show tables" | $SQLCMD | grep -v -P "^Tables_in_"$SQL_DB | grep -v -P "^audit$"); do
TMONTH=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $2;exit') TMONTH=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $1;exit')
TYEAR=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $3;exit') TYEAR=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $2;exit')
# Drop table if older than configured retention # Drop table if older than configured retention
if [ "$(($(date -d "01/$MONTH/$YEAR" +%s)-$(date -d "01/$TMONTH/$TYEAR" +%s)))" -gt "$((24*3600*$RETENTION))" ]; then if [ "$(($(date -d "01/$MONTH/$YEAR" +%s)-$(date -d "01/$TMONTH/$TYEAR" +%s)))" -gt "$((24*3600*$RETENTION))" ]; then
echo "DROP TABLE $T;" | $SQLCMD echo "DROP TABLE $T;" | $SQLCMD

Loading…
Cancel
Save