Script - Better than PurgeWhenFull
Posted: Sat Jun 16, 2007 4:35 pm
I am running an older version of ZM, but I wanted to post this into the current release, as I believe it may be usefull still.
I have seven cameras, and the problem with PurgeWhenFull is that it does not pick the image directory that is fullest. When they fill up to 32K files, the images stop recording.
Deleting the images is only part of the problem, as there are still entries in the database which need to be purged as well.
I wrote these crummy scripts (I was lazy) and they do the job wonderfully. I wanted to share them.
The script also preserves your archived images.
Here is my crontab entry:
0 10 * * * /usr/local/bin/zmclean 1 > /dev/null 2>&1
1 10 * * * /usr/local/bin/zmclean 4 > /dev/null 2>&1
2 10 * * * /usr/local/bin/zmclean 7 > /dev/null 2>&1
3 10 * * * /usr/local/bin/zmclean 8 > /dev/null 2>&1
4 10 * * * /usr/local/bin/zmclean 9 > /dev/null 2>&1
5 10 * * * /usr/local/bin/zmclean 11 > /dev/null 2>&1
6 10 * * * /usr/local/bin/zmclean 12 > /dev/null 2>&1
zmclean:
#!/bin/bash
if [ x$1 == x ]
then
echo "missing param"
exit 1
fi
folder="/var/www/html/events/$1"
cd $folder
p=`/bin/pwd`
if [ x$p != x/var/www/html/events/$1 ]
then
echo "wrong folder"
exit 1
fi
/usr/bin/find . -type d -mtime +30 -exec /usr/local/bin/zmzap {} \;
and
zmzap:
#!/bin/bash
if [ x$1 == x ]
then
echo "missing param"
exit 1
fi
echo $1 | grep './'
if [ $? == 0 ]
then
targ=`echo $1 | /bin/cut -c 3-`
else
targ=$1
fi
if [ ! -d $targ ]
then
echo "missing target dir"
exit 1
fi
x=`/usr/bin/mysql -uzm -pzm << YYYY
use zm;
select Archived from Events where id = $targ;
quit
YYYY
`
y=`echo $x | /bin/cut -c 10`
if [ $y == 1 ]
then
echo "archived"
exit 0
fi
echo $targ
/bin/rm -rf $targ
/usr/bin/mysql -uzm -pzm << XXXX
use zm;
delete from Events where id = $targ;
delete from Frames where EventId = $targ;
quit
XXXX
I have seven cameras, and the problem with PurgeWhenFull is that it does not pick the image directory that is fullest. When they fill up to 32K files, the images stop recording.
Deleting the images is only part of the problem, as there are still entries in the database which need to be purged as well.
I wrote these crummy scripts (I was lazy) and they do the job wonderfully. I wanted to share them.
The script also preserves your archived images.
Here is my crontab entry:
0 10 * * * /usr/local/bin/zmclean 1 > /dev/null 2>&1
1 10 * * * /usr/local/bin/zmclean 4 > /dev/null 2>&1
2 10 * * * /usr/local/bin/zmclean 7 > /dev/null 2>&1
3 10 * * * /usr/local/bin/zmclean 8 > /dev/null 2>&1
4 10 * * * /usr/local/bin/zmclean 9 > /dev/null 2>&1
5 10 * * * /usr/local/bin/zmclean 11 > /dev/null 2>&1
6 10 * * * /usr/local/bin/zmclean 12 > /dev/null 2>&1
zmclean:
#!/bin/bash
if [ x$1 == x ]
then
echo "missing param"
exit 1
fi
folder="/var/www/html/events/$1"
cd $folder
p=`/bin/pwd`
if [ x$p != x/var/www/html/events/$1 ]
then
echo "wrong folder"
exit 1
fi
/usr/bin/find . -type d -mtime +30 -exec /usr/local/bin/zmzap {} \;
and
zmzap:
#!/bin/bash
if [ x$1 == x ]
then
echo "missing param"
exit 1
fi
echo $1 | grep './'
if [ $? == 0 ]
then
targ=`echo $1 | /bin/cut -c 3-`
else
targ=$1
fi
if [ ! -d $targ ]
then
echo "missing target dir"
exit 1
fi
x=`/usr/bin/mysql -uzm -pzm << YYYY
use zm;
select Archived from Events where id = $targ;
quit
YYYY
`
y=`echo $x | /bin/cut -c 10`
if [ $y == 1 ]
then
echo "archived"
exit 0
fi
echo $targ
/bin/rm -rf $targ
/usr/bin/mysql -uzm -pzm << XXXX
use zm;
delete from Events where id = $targ;
delete from Frames where EventId = $targ;
quit
XXXX