Limit Diskspace for a cam
- biologisch
- Posts: 96
- Joined: Fri Aug 24, 2007 10:37 am
Limit Diskspace for a cam
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...
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.36.33
zmeventnotification Version = "6.1.28"
zmeventnotification Version = "6.1.28"
- biologisch
- Posts: 96
- Joined: Fri Aug 24, 2007 10:37 am
Re: Limit Diskspace for a cam
But how I can do that? Disk Blocks, Percent, Space filter relates to the whole disk, not only for a monitor?
ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
zmeventnotification Version = "6.1.28"
- biologisch
- Posts: 96
- Joined: Fri Aug 24, 2007 10:37 am
Re: Limit Diskspace for a cam
Now I will answer my question:
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.
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:
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.
Permanent loop device
Put in /etc/fstab
/path/to/device /path/to/mountpoint filesystemtype options
/ /mnt /ext4 loop
Than reboot.
In Zoneminder goto and add the new Disks.
Than in point to the new Disk.
We now need a filter, that will delete on our new storage area. Navigate to filters from the console. Thats it. I hope it helps.

Code: Select all
$ dd if=/dev/zero of=disk.img bs=1G count=5
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
Now we can mount the image file by using the mount command:
Code: Select all
$ sudo mount -o loop disk.img ~/HDD
Unmounting the image by using command line.
Code: Select all
$ sudo umount ~/HDD
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
Than in
Code: Select all
-> Monitor -> Source -> Storage -> Storage Aera
We now need a filter, that will delete on our new storage area. Navigate to filters from the console. Thats it. I hope it helps.

ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
zmeventnotification Version = "6.1.28"
Re: Limit Diskspace for a cam
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.
In any case, thanks again. I've added a link to this page from the wiki.
fastest way to test streams:
ffmpeg -i rtsp://<user>:<pass>@<ipaddress>:554/path ./output.mp4 (if terminal only)
ffplay rtsp://<user>:<pass>@<ipaddress>:554/path (gui)
find paths on ispydb or in zm hcl
If you are new to security software, read:
https://wiki.zoneminder.com/Dummies_Guide
ffmpeg -i rtsp://<user>:<pass>@<ipaddress>:554/path ./output.mp4 (if terminal only)
ffplay rtsp://<user>:<pass>@<ipaddress>:554/path (gui)
find paths on ispydb or in zm hcl
If you are new to security software, read:
https://wiki.zoneminder.com/Dummies_Guide
-
- Posts: 38
- Joined: Fri Jun 12, 2020 1:29 pm
Re: Limit Diskspace for a cam
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.
I got this from stackoverflow btw, not my code. Works wonderfully though and is very fast.
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
- biologisch
- Posts: 96
- Joined: Fri Aug 24, 2007 10:37 am
Re: Limit Diskspace for a cam
Does the database update by it self? 

ZM Versions = 1.36.33
zmeventnotification Version = "6.1.28"
zmeventnotification Version = "6.1.28"
-
- Posts: 38
- Joined: Fri Jun 12, 2020 1:29 pm
Re: Limit Diskspace for a cam
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.
-
- Posts: 38
- Joined: Fri Jun 12, 2020 1:29 pm
Re: Limit Diskspace for a cam
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.
Re: Limit Diskspace for a cam
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 ...BaconButty wrote: ↑Sun Jun 21, 2020 3:33 pm find /var/cache/zoneminder/HighResCamEvents -maxdepth 5 -type f -printf '%T@\>
Code: Select all
-printf '%T@\t%s\t%p\n'>
-
- Posts: 38
- Joined: Fri Jun 12, 2020 1:29 pm
Re: Limit Diskspace for a cam
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.