Limit Diskspace for a cam

Forum for questions and support relating to 1.35.x development only.
Post Reply
User avatar
biologisch
Posts: 84
Joined: Fri Aug 24, 2007 10:37 am

Limit Diskspace for a cam

Post by biologisch » Tue Apr 14, 2020 1:44 pm

Hi!
I try to limit the diskspace for a specific cam with filter rules - for example: Monitor 1 = 5 GB, Monitor 2 = 2 GB
Is this possible with filter rules?

Thank you in advance...
ZM Versions = 1.35.x (multiple Server)
zmeventnotification Version = "5.15.7"
https://zoneminder.miraheze.org

User avatar
iconnor
Posts: 1388
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Limit Diskspace for a cam

Post by iconnor » Wed Apr 15, 2020 2:33 am

yes

User avatar
biologisch
Posts: 84
Joined: Fri Aug 24, 2007 10:37 am

Re: Limit Diskspace for a cam

Post by biologisch » Wed Apr 15, 2020 6:28 am

But how I can do that? Disk Blocks, Percent, Space filter relates to the whole disk, not only for a monitor?
ZM Versions = 1.35.x (multiple Server)
zmeventnotification Version = "5.15.7"
https://zoneminder.miraheze.org

User avatar
biologisch
Posts: 84
Joined: Fri Aug 24, 2007 10:37 am

Re: Limit Diskspace for a cam

Post by biologisch » Fri Jun 12, 2020 9:37 am

Now I will answer my question: :D

Code: Select all

$ dd if=/dev/zero of=disk.img bs=1G count=5
Note: The command execution time depends on the size of the image you have opted out for.

The if param stands for input file to refer the input file. As if, of stands for output file and this will create the .img file with the name you specify. The third param bs stands for block size. This will let you set the size of the image file. The G in the above command stands for GigaByte (GB). You can set the image size by specifying the block size. In this case G stands for GigaBytes (GB), K for KiloBytes (KB), T for TeraBytes (TB), P for Petabytes (PB) and so on. Here I am creating a 5 blocks of 1 GB each for the image file name disk.

This command will create the .img file but you cannot mount this file as of yet. To do that you have to format the image so that it can have a file system. To do this make use of mkfs command.

Code: Select all

$ mkfs ext4 -F disk.img
I am creating an ext4 filesystem on my image file. -F is to force the operation. Here is the output of the command.

Now we can mount the image file by using the mount command:

Code: Select all

$ sudo mount -o loop disk.img ~/HDD
With the success of the above command, you can see the image mounted on your desktop. You can unmount the image by clicking the eject or unmount button as shown in the below screenshot or you can execute the umount command to do that.

Unmounting the image by using command line.

Code: Select all

$ sudo umount ~/HDD
Permanent loop device
Put in /etc/fstab
/path/to/device /path/to/mountpoint filesystemtype options
/ /mnt /ext4 loop

Than reboot.
In Zoneminder goto

Code: Select all

-> Options -> Storage
and add the new Disks.
Than in

Code: Select all

-> Monitor -> Source -> Storage -> Storage Aera
point to the new Disk.
Zoneminder-Disks.png
Zoneminder-Disks.png (59.53 KiB) Viewed 2620 times

We now need a filter, that will delete on our new storage area. Navigate to filters from the console.
600px-Filter.png
600px-Filter.png (76.92 KiB) Viewed 2618 times
Thats it. I hope it helps. ;-)
ZM Versions = 1.35.x (multiple Server)
zmeventnotification Version = "5.15.7"
https://zoneminder.miraheze.org

burger
Posts: 189
Joined: Mon May 11, 2020 4:32 pm

Re: Limit Diskspace for a cam

Post by burger » Fri Jun 12, 2020 1:58 pm

That is a useful guide for gnulinux in general, thanks. With ZM though, would it be a concern if you had a number of these disk images on the HDD, that they would cause the HDD writes to jump around the disk? Wouldn't these be contiguous/sequential blocks?

In any case, thanks again. I've added a link to this page from the wiki.
fastest way to test streams:
ffmpeg -i rtsp://<ipaddress>:554/path output.mp4
from terminal, and run through paths on ispydb or in zm hcl

If you are new to cctv, read this:
https://wiki.zoneminder.com/Dummies_Guide

BaconButty
Posts: 27
Joined: Fri Jun 12, 2020 1:29 pm

Re: Limit Diskspace for a cam

Post by BaconButty » Fri Jun 12, 2020 2:21 pm

Just about to post a question on this myself, since you've posted an excellent helpful solution, I thought I'd throw mine in here.
This has an issue that the events are being stuck in zoneminder after being deleted, but I use this bash script run every hour to keep the events folder below 10gb by deleting the oldest files until this is achieved.

Code: Select all

#!/bin/bash
usage=$(du -sb /var/cache/zoneminder/events | cut -d $'\t' -f 1)
max=1000000000
if (( usage > max ))
then
  find /var/cache/zoneminder/events -maxdepth 5 -type f -printf '%T@\t%s\t%p\n'>
    while (( usage > max )) && IFS=$'\t' read timestamp size file
    do
      rm -- "$file" && (( usage -= size ))
    done
fi
I got this from stackoverflow btw, not my code. Works wonderfully though and is very fast.

User avatar
biologisch
Posts: 84
Joined: Fri Aug 24, 2007 10:37 am

Re: Limit Diskspace for a cam

Post by biologisch » Fri Jun 12, 2020 4:33 pm

Does the database update by it self? :roll:
ZM Versions = 1.35.x (multiple Server)
zmeventnotification Version = "5.15.7"
https://zoneminder.miraheze.org

BaconButty
Posts: 27
Joined: Fri Jun 12, 2020 1:29 pm

Re: Limit Diskspace for a cam

Post by BaconButty » Fri Jun 12, 2020 4:57 pm

No, we need to call Zoneminder to audit the events after, I'm having an issue getting this working. When I figure it out I'll update here.

BaconButty
Posts: 27
Joined: Fri Jun 12, 2020 1:29 pm

Re: Limit Diskspace for a cam

Post by BaconButty » Sun Jun 21, 2020 3:33 pm

biologisch, I have that script done. Just in case you're interested. The secret was calling zmaudit.pl twice.

Code: Select all


#!/bin/bash
usage=$(du -sb /var/cache/zoneminder/HighResCamEvents  | cut -d $'\t' -f 1)
max=10000000000
if (( usage > max ))
then
  find /var/cache/zoneminder/HighResCamEvents -maxdepth 5 -type f -printf '%T@\t%s\t%p\n' | sort -n | \
    while (( usage > max )) && IFS=$'\t' read timestamp size file
    do
      rm -- "$file" && (( usage -= size ))
    done
fi
zmaudit.pl
zmaudit.pl


Last edited by BaconButty on Sun Jun 21, 2020 3:56 pm, edited 1 time in total.

mikb
Posts: 478
Joined: Mon Mar 25, 2013 12:34 pm

Re: Limit Diskspace for a cam

Post by mikb » Sun Jun 21, 2020 3:51 pm

BaconButty wrote:
Sun Jun 21, 2020 3:33 pm
find /var/cache/zoneminder/HighResCamEvents -maxdepth 5 -type f -printf '%T@\>
Can you check and edit this post, as it looks like part of the printf got munched away (here AND in your other posting of it) -- there's an unbalanced quote which made me notice ...

Code: Select all

 -printf '%T@\t%s\t%p\n'>

BaconButty
Posts: 27
Joined: Fri Jun 12, 2020 1:29 pm

Re: Limit Diskspace for a cam

Post by BaconButty » Sun Jun 21, 2020 3:57 pm

Thanks a lot mikb! I just wanted to share that before I forgot about it and quickly copied and pasted from putty. I should have been more careful.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest