Page 1 of 1

back to deleting events on low disk space

Posted: Thu Sep 18, 2003 8:54 pm
by laad
Hi

I think it should be possible to do in another way too (not via filters):
there can be situations when
1) the program should keep as much data as it can (simple example: a roberry had a place and it was noticed only after, say, several weeks)
2) you estimated the place several days of record shoudl consume and adjust a fiter to suit it, but some unexpected heavy traffic had place and your deamons are shutted

So, I suggest it'd be nice if some code's added to zmfilter.pl monitoring for amount of disk space and deleting as much as needed events in case of low disk space(another variable to hold in configure?)

Best regards, Alexander

addon

Posted: Fri Sep 19, 2003 12:52 pm
by laad
here's a code that seems to be working (to be inserted into while (1) in zmfilter.pl):

#low disk space part
use constant ZM_DISKLOWLIMIT => 100; #in Mbs
use integer;
my $bindf='/bin/df';
my $partition='/'; #FIXME: to be set elsewhere
my $dfree=0;
my $st=0;
while ($st == 0) {
open (DF,"$bindf $partition |") or die("Can't execute: $bindf\n");
$_=<DF>;$_=<DF>;
my @tab=split /\s+/;
$dfree=$tab[3]/1024;print "space free on $partition: ${dfree}Mb\n" if (VERBOSE);
close(DF);
if ($dfree<ZM_DISKLOWLIMIT) {
my $sql="select Id, MonitorId from Events order by Id limit 1";
my $sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
my $res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my ($event_id,$monitor_id)=$sth->fetchrow_array();if (!defined($event_id)) {
print "warning: low disk space, yet nothing to delete!\n";
$st=1;
} else {
print "id to delete: $event_id (on monitor $monitor_id)\n" if (VERBOSE);
$sth->finish();
$sql="select Name from Monitors where Id = $monitor_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
my $row=$sth->fetchrow_hashref();
my $monitor_name=$row->{Name};
$sth->finish();
print "Deleting $event_id due to disk space runnig low\n";
my $cmd="/bin/rm -rf ".EVENT_PATH."/$monitor_name/$event_id";
qx($cmd);
$sql="delete from Events where Id = $event_id";
$sth=$dbh->prepare_cached($sql) or die ("Can't prepare '$sql': ".$dbh->errstr());
$res=$sth->execute() or die("Can't execute: ".$sth->errstr());
$sth->finish();
}
#zmaudit.pl is to clean up datebase stuff
} else {$st=1;}
}
#

Re: back to deleting events on low disk space

Posted: Thu Oct 02, 2003 2:38 pm
by zoneminder
Hi Borodin,

Thanks for suggesting this. I'll try and put something along these lines into the next release.

Cheers,

Phil

Re: back to deleting events on low disk space

Posted: Thu Feb 12, 2004 4:15 pm
by pavel
Hi Phil,

this is the feature I still missing in current version 1.17.2.
It would be great to possibility of automatically deletion the oldest event (or maybe some time range - x days?) on low disk space.

Best regards,
Pavel

Re: back to deleting events on low disk space

Posted: Thu Feb 12, 2004 6:02 pm
by victor_diago
I have made an autoclean.sh script that check (via crond) if the free space of the disk is under X MB and , if it is, it enter the directories and delete all the events of the oldest day, in every monitor...

this should help... i have sent it to the general discussion forum, at the title "new autoclean script for events"


i am using it a lot :)

back to deleting events on low disk space

Posted: Fri Apr 16, 2004 10:25 am
by mapasainformatica
i test this script.
I add the text in zmfilter.pl but this is the error:

zmfilter.pl
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 216, near "=;"
syntax error at /usr/local/bin/zmfilter.pl line 221, near "$dfree my "
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 221.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 222.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 230.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 231.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 240.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
Global symbol "$sql" requires explicit package name at /usr/local/bin/zmfilter.pl line 241.
syntax error at /usr/local/bin/zmfilter.pl line 247, near "} else"
/usr/local/bin/zmfilter.pl has too many errors.