Page 1 of 1

Limit Diskspace for a cam

Posted: Tue Apr 14, 2020 1:44 pm
by biologisch
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...

Re: Limit Diskspace for a cam

Posted: Wed Apr 15, 2020 2:33 am
by iconnor
yes

Re: Limit Diskspace for a cam

Posted: Wed Apr 15, 2020 6:28 am
by biologisch
But how I can do that? Disk Blocks, Percent, Space filter relates to the whole disk, not only for a monitor?

Re: Limit Diskspace for a cam

Posted: Fri Jun 12, 2020 9:37 am
by biologisch
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 9290 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 9288 times
Thats it. I hope it helps. ;-)

Re: Limit Diskspace for a cam

Posted: Fri Jun 12, 2020 1:58 pm
by burger
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.

Re: Limit Diskspace for a cam

Posted: Fri Jun 12, 2020 2:21 pm
by BaconButty
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.

Re: Limit Diskspace for a cam

Posted: Fri Jun 12, 2020 4:33 pm
by biologisch
Does the database update by it self? :roll:

Re: Limit Diskspace for a cam

Posted: Fri Jun 12, 2020 4:57 pm
by BaconButty
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.

Re: Limit Diskspace for a cam

Posted: Sun Jun 21, 2020 3:33 pm
by BaconButty
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



Re: Limit Diskspace for a cam

Posted: Sun Jun 21, 2020 3:51 pm
by mikb
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'>

Re: Limit Diskspace for a cam

Posted: Sun Jun 21, 2020 3:57 pm
by BaconButty
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.