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