spacing. Add code to delete events that huse the deep storage scheme and have lost their symlinks.
This commit is contained in:
parent
fd72689182
commit
c285d5ebb1
|
@ -252,36 +252,37 @@ MAIN: while( $loop ) {
|
||||||
foreach my $day_dir ( @day_dirs ) {
|
foreach my $day_dir ( @day_dirs ) {
|
||||||
Debug( "Checking day dir $day_dir" );
|
Debug( "Checking day dir $day_dir" );
|
||||||
( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint
|
( $day_dir ) = ( $day_dir =~ /^(.*)$/ ); # De-taint
|
||||||
if ( ! chdir( $day_dir ) ) {
|
if ( !chdir($day_dir) ) {
|
||||||
Error( "Can't chdir to '$$Storage{Path}/$day_dir': $!" );
|
Error("Can't chdir to '$$Storage{Path}/$day_dir': $!");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ( ! opendir( DIR, '.' ) ) {
|
if ( ! opendir(DIR, '.') ) {
|
||||||
Error( "Can't open directory '$$Storage{Path}/$day_dir': $!" );
|
Error("Can't open directory '$$Storage{Path}/$day_dir': $!");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
my @event_links = sort { $b <=> $a } grep { -l $_ } readdir( DIR );
|
my @event_links = sort { $b <=> $a } grep { -l $_ } readdir( DIR );
|
||||||
closedir( DIR );
|
Debug("Have " . @event_links . ' event links');
|
||||||
|
closedir(DIR);
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
foreach my $event_link ( @event_links ) {
|
foreach my $event_link ( @event_links ) {
|
||||||
if ( $event_link =~ /[^\d\.]/ ) {
|
if ( $event_link =~ /[^\d\.]/ ) {
|
||||||
Warning("Non-event link found $event_link in $day_dir, skipping");
|
Warning("Non-event link found $event_link in $day_dir, skipping");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
Debug( "Checking link $event_link" );
|
Debug("Checking link $event_link");
|
||||||
( my $event = $event_link ) =~ s/^.*\.//;
|
( my $event = $event_link ) =~ s/^.*\.//;
|
||||||
#Event path is hour/minute/sec
|
#Event path is hour/minute/sec
|
||||||
my $event_path = readlink( $event_link );
|
my $event_path = readlink($event_link);
|
||||||
|
|
||||||
if ( !($event_path and -e $event_path) ) {
|
if ( !($event_path and -e $event_path) ) {
|
||||||
aud_print( "Event link $day_dir/$event_link does not point to valid target" );
|
aud_print("Event link $day_dir/$event_link does not point to valid target");
|
||||||
if ( confirm() ) {
|
if ( confirm() ) {
|
||||||
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
|
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
|
||||||
unlink( $event_link );
|
unlink($event_link);
|
||||||
$cleaned = 1;
|
$cleaned = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Debug( "Checking link $event_link points to $event_path " );
|
Debug("Checking link $event_link points to $event_path ");
|
||||||
my $Event = $fs_events->{$event} = new ZoneMinder::Event();
|
my $Event = $fs_events->{$event} = new ZoneMinder::Event();
|
||||||
$$Event{Id} = $event;
|
$$Event{Id} = $event;
|
||||||
$$Event{Path} = join('/', $Storage->Path(), $day_dir,$event_path);
|
$$Event{Path} = join('/', $Storage->Path(), $day_dir,$event_path);
|
||||||
|
@ -292,6 +293,42 @@ MAIN: while( $loop ) {
|
||||||
$Event->DiskSpace( undef );
|
$Event->DiskSpace( undef );
|
||||||
} # event path exists
|
} # event path exists
|
||||||
} # end foreach event_link
|
} # end foreach event_link
|
||||||
|
|
||||||
|
# Now check for events that have lost their link
|
||||||
|
|
||||||
|
my @time_dirs = glob('[0-9][0-9]/[0-9][0-9]/[0-9][0-9]');
|
||||||
|
foreach my $event_dir ( @time_dirs ) {
|
||||||
|
Debug("Checking time dir $event_dir");
|
||||||
|
( $event_dir ) = ( $event_dir =~ /^(.*)$/ ); # De-taint
|
||||||
|
|
||||||
|
my $event_id = undef;
|
||||||
|
|
||||||
|
my @mp4_files = glob("$event_dir/[0-9]+\-video.mp4");
|
||||||
|
foreach my $mp4_file ( @mp4_files ) {
|
||||||
|
my ( $id ) = $mp4_file =~ /^([0-9]+)\-video\.mp4$/;
|
||||||
|
if ( $id ) {
|
||||||
|
$event_id = $id;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $event_id ) {
|
||||||
|
my $Event = $fs_events->{$event_id} = new ZoneMinder::Event();
|
||||||
|
$$Event{Id} = $event_id;
|
||||||
|
$$Event{Path} = join('/', $Storage->Path(), $day_dir, $event_dir);
|
||||||
|
$$Event{RelativePath} = join('/', $day_dir, $event_dir);
|
||||||
|
$$Event{Scheme} = 'Deep';
|
||||||
|
$Event->MonitorId( $monitor_dir );
|
||||||
|
$Event->StorageId( $Storage->Id() );
|
||||||
|
$Event->DiskSpace( undef );
|
||||||
|
} else {
|
||||||
|
aud_print("Deleting event directories with no event id information at $day_dir/$event_dir");
|
||||||
|
if ( confirm() ) {
|
||||||
|
my $command = "rm -rf $event_dir";
|
||||||
|
executeShellCommand( $command );
|
||||||
|
$cleaned = 1;
|
||||||
|
}
|
||||||
|
} # end if able to find id
|
||||||
|
} # end foreach event_dir without link
|
||||||
chdir( $Storage->Path() );
|
chdir( $Storage->Path() );
|
||||||
} # end foreach day dir
|
} # end foreach day dir
|
||||||
}
|
}
|
||||||
|
@ -701,17 +738,18 @@ FROM Frames WHERE EventId=?';
|
||||||
if ( $Config{ZM_LOG_DATABASE_LIMIT} =~ /^(.*)s$/ ) {
|
if ( $Config{ZM_LOG_DATABASE_LIMIT} =~ /^(.*)s$/ ) {
|
||||||
$Config{ZM_LOG_DATABASE_LIMIT} = $1;
|
$Config{ZM_LOG_DATABASE_LIMIT} = $1;
|
||||||
}
|
}
|
||||||
my $deleteLogByTimeSql =
|
my $deleted_rows;
|
||||||
'DELETE low_priority FROM Logs
|
do {
|
||||||
WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')';
|
my $deleteLogByTimeSql =
|
||||||
my $deleteLogByTimeSth = $dbh->prepare_cached( $deleteLogByTimeSql )
|
'DELETE FROM Logs
|
||||||
or Fatal( "Can't prepare '$deleteLogByTimeSql': ".$dbh->errstr() );
|
WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.') LIMIT 10';
|
||||||
$res = $deleteLogByTimeSth->execute()
|
my $deleteLogByTimeSth = $dbh->prepare_cached( $deleteLogByTimeSql )
|
||||||
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
or Fatal( "Can't prepare '$deleteLogByTimeSql': ".$dbh->errstr() );
|
||||||
if ( $deleteLogByTimeSth->rows() ){
|
$res = $deleteLogByTimeSth->execute()
|
||||||
aud_print( 'Deleted '.$deleteLogByTimeSth->rows()
|
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
||||||
." log table entries by time\n" );
|
$deleted_rows = $deleteLogByTimeSth->rows();
|
||||||
}
|
aud_print( "Deleted $deleted_rows log table entries by time\n" );
|
||||||
|
} while ( $deleted_rows );
|
||||||
}
|
}
|
||||||
} # end if ZM_LOG_DATABASE_LIMIT
|
} # end if ZM_LOG_DATABASE_LIMIT
|
||||||
$loop = $continuous;
|
$loop = $continuous;
|
||||||
|
|
Loading…
Reference in New Issue