How to delete many events quickly?

Forum for questions and support relating to the 1.30.x releases only.
Locked
wh33lz
Posts: 24
Joined: Tue Aug 15, 2017 8:19 pm
Location: Toronto

How to delete many events quickly?

Post by wh33lz »

One of my cameras "flipped out" and created thousands (43K) of "blue screen" events.
How can I delete these quickly?
Creating and executing a filter is unreasonablely slow, manually deleting each page of events (1700 pages) is not feasible.
I suppose deleting (rm -rf *.jpg) files directly from the camera's event folder will work, but what other steps...files/folders/database..are required?

Solution Update:
Step 1: Stop the Zoneminder service :
Method 1: Click on "Running" at top of the Zoneminder Console, Select Stop and Apply
Method 2: From server commandline (Ubuntu 16.04 in my case) "sudo systemctl stop zoneminder"
Confirm Zoneminder Service is stopped "sudo systemctl status zoneminder"
The result should look like

Code: Select all

user@your_server:/var/cache/zoneminder/events/2/18/05/05$ sudo systemctl status zoneminder
● zoneminder.service - ZoneMinder CCTV recording and surveillance system
   Loaded: loaded (/lib/systemd/system/zoneminder.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2018-05-05 21:25:04 EDT; 8s ago
  Process: 26266 ExecStop=/usr/bin/zmpkg.pl stop (code=exited, status=0/SUCCESS)
  Process: 24209 ExecStart=/usr/bin/zmpkg.pl start (code=exited, status=0/SUCCESS)
 Main PID: 24225 (code=exited, status=0/SUCCESS)

May 05 21:24:51 your_server sudo[26275]:     root : TTY=unknown ; PWD=/usr/share/zoneminder/www ; USER=www-data ; COMMAND=/bin/true
May 05 21:24:51 your_server sudo[26275]: pam_unix(sudo:session): session opened for user www-data by (uid=0)
May 05 21:24:51 your_server sudo[26275]: pam_unix(sudo:session): session closed for user www-data
May 05 21:24:51 your_server sudo[26277]:     root : TTY=unknown ; PWD=/usr/share/zoneminder/www ; USER=www-data ; COMMAND=/usr/bin/zmdc.pl check
May 05 21:24:51 your_server sudo[26277]: pam_unix(sudo:session): session opened for user www-data by (uid=0)
May 05 21:24:52 your_server sudo[26277]: pam_unix(sudo:session): session closed for user www-data
May 05 21:24:52 your_server sudo[26280]:     root : TTY=unknown ; PWD=/usr/share/zoneminder/www ; USER=www-data ; COMMAND=/usr/bin/zmdc.pl shutdown
May 05 21:24:52 your_server sudo[26280]: pam_unix(sudo:session): session opened for user www-data by (uid=0)
May 05 21:25:03 your_server sudo[26280]: pam_unix(sudo:session): session closed for user www-data
May 05 21:25:04 your_server systemd[1]: Stopped ZoneMinder CCTV recording and surveillance system.
Step 2: Locate your Zoneminder events folder. ( sudo find / -name Zoneminder )
In my case I use a dedicated drive as outlined in the Wiki @ https://wiki.zoneminder.com/Using_a_ded ... Hard_Drive, so my events folder is at /CamDrive/Zoneminder/events/
Next, navigate to the camera folder you wish to clear. For example /CamDrive/Zoneminder/events/Camera1
The subfolders in the camera folders are numbered according to the Year/Month/Day/Hour/Minute/Seconds
So events for my Camera1 on April 5th 2018 would be in my folder /CamDrive/Zoneminder/events/Camera1/18/04/05
To delete all events for Camera1 in April 2018, I would run sudo rm -fr /CamDrive/Zoneminder/events/Camera1/18/04
To delete all events for Camera1 on April 5th 2018, I would run sudo rm -fr /CamDrive/Zoneminder/events/Camera1/18/04/05
To delete all events for Camera1 in 2018, I would run sudo rm -fr /CamDrive/Zoneminder/events/Camera1/18

Step 3: Restart Zoneminder service using Zoneminder Console, or, commandline sudo systemctl start zoneminder
The Zoneminder database should eventually update itself to the changes.
Note: Depending on how your installation is configured, you may need to go into the Options/System and activate RUN_AUDIT.
Last edited by wh33lz on Sun May 13, 2018 3:05 pm, edited 6 times in total.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: How to delete many events quickly?

Post by mikb »

"rm -rf *.jpg" won't do what you mean, you'd need something more like

cd /where/your/events/live/the/camera/the/date
find . -type f -iname "*.jpg" -delete

This will blow away all .jpgs from "here" down without further prompting! Make sure you're blowing the correct bits away :)

ZM Audit will then have a job of clearing up all the database entries.
wh33lz
Posts: 24
Joined: Tue Aug 15, 2017 8:19 pm
Location: Toronto

Re: How to delete many events quickly?

Post by wh33lz »

Yes. I meant running that command from the events folder for that specific camera. I will edit my OP so noone makes that mistake.
These events are over multiple dates and are not archived , so in my case, I can delete all events for that camera. Others users may have a different scenario.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: How to delete many events quickly?

Post by mikb »

It's not that it might delete something else: That command will NOT delete the buried jpgs deep into the tree. You are expecting too much from just adding "-r" :) My point was it won't recurse looking for jpegs.

The "*.jpg" will be expanded by the shell as "there are no jpgs in this current directory" so nothing will get deleted.

Unless you plan to go into each directory for each event and do "rm *.jpg", which will bore you silly!

Your updated post is more sensible, in that you are pruning the entire branch for a camera, or on a particular day etc. That won't fall foul of expecting too much from rm.
wh33lz
Posts: 24
Joined: Tue Aug 15, 2017 8:19 pm
Location: Toronto

Re: How to delete many events quickly?

Post by wh33lz »

That step worked fine , but zmaudit is not updating the database.
I can see by the PID it is running, and I tried all the options...set it to run, set it to remove any items older than 12 hours etc, but I still have 43K/1700 pages of events listed for that camera after 2 days.
Guess I will need to update the database myself...
Would you know if I remove that camera from the console, will it be immediately removed from the database? Either way, I figure it will be easier to just remove the camera and all associated tables and entries from the database.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: How to delete many events quickly?

Post by mikb »

ZM Audit has never (as far as I know) left behind a load of entries when the files are gone. More likely it enthusiastically wipes database entries at the first sign the files are missing!

Maybe others could suggest how to give ZM audit a kick to do the right thing, if the files have gone -- I'm not much for digging into the database manually.
wh33lz
Posts: 24
Joined: Tue Aug 15, 2017 8:19 pm
Location: Toronto

Re: How to delete many events quickly?

Post by wh33lz »

Ran through the steps to run zmaudit one more time, and it cleaned out the database overnight!
All is well now.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: How to delete many events quickly?

Post by mikb »

Ah, the secret operations of ZM Audit while you sleep ... glad it's sorted now.
Locked