Code: Select all
#!/bin/bash
# This is the Second version of autoclean.sh for ZM Events.
# autoclean.sh will remove (from filesystem AND database)
# the oldest day, when your free disk amount is less than
# the value defined in "lessdiskamount"
#
# See that This WILL NOT remove ARCHIVED events
# so this is a very safe way to remove old events
#
# ZM (ZoneMinder) is the top Surveillance System in Linux
# and its manteined by Philip Coombes.
#
# Fell Free to contact me (Victor Diago) in vdiago@spymac.com
#
# With a little help we could make ZM Always Better.
#
# Victor Diago
# Put your partition (like hda1) where your events are. this is used to determine
# available space.
partition="your partition"
# Put here your DataBase Name
database="your db name (default zm)"
# Script will clean the oldest day when free space is less than XXX MB
#lessdiskamount="less disk amount to allow (IN MB)"
lessdiskamount="500"
# Your ROOT DB username
rootdb="root s db username"
# Your ROOT DB password
rootpass="root s db password"
# Now we will calculate how much free space you have actually
freeamount=`df -m|grep "$partition"|cut -c 42-50|sed s/" "/""/g`
# Now we need to calculate the last day recorded without Archive flag
lastday=`mysql -B -u "$rootdb" --password="$rootpass" -e "use zm;select StartTime from Events where Archived <> 1 limit 1;"|tail -1|cut -f1 -d " "`
while [ "$freeamount" -lt "$lessdiskamount" ];
do
mysql -B -u "$rootdb" --password="$rootpass" -e "use zm;delete from Events where StartTime LIKE '"$lastday"%' and Archived <> 1;"
/usr/local/bin/zmaudit.pl -y
sleep 5
freeamount=`df -m|grep "$partition"|cut -c 42-50|sed s/" "/""/g`
sleep 1
done;
victor diago