Page 1 of 1

Events has been purged after power outage

Posted: Thu Feb 25, 2016 12:42 pm
by martyouel
Hi,

I'm using ZoneMinder since now 1 week and I love it.

Here's my setup :

- ZoneMinder running on a RPI2
- Trendnet IP CAM
- Dedicated USB Flash Drive to store events

Yesterday, there have been some power outage in my sector.
So my setup has been restarted maybe 4-5 times while the evening/night.

This morning, when I logged in ZM, I saw that all my events has been deleted. I have only the news events since this morning.
I took a look on the flashdrive...almost empty.
I did a select in the table Events of the database...almost empty.

Somebody knows what could happen ?

thanks in advance

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 12:50 pm
by knight-of-ni
Where and how is your ZoneMinder event folder mounted to?

This can happen if the event folder is unavailable at the time ZoneMinder is started.

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 12:59 pm
by martyouel
On my external drive.

I followed this guide https://wiki.zoneminder.com/Using_a_ded ... Hard_Drive and added "alternate location" in my fstab.

Here's my fstab :

UUID=7A6E03F96E03AD47 /mnt/rasp-ext ntfs auto,users,rw,uid=33,gid=33,umask=0002 0 0
/mnt/rasp-ext/zoneminder/images /var/cache/zoneminder/images none defaults,bind 0 2
/mnt/rasp-ext/zoneminder/events /var/cache/zoneminder/events none defaults,bind 0 2

Thanks

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 1:27 pm
by knight-of-ni
Yep, that's the right guide, but I wouldn't recommend using an ntfs filesystem for your event folder.
One should use a Linux native filesystem for the event folder.

NTFS-3G does not appear to have full support for junctions (a.k.a. symlinks) as mentioned here:
http://superuser.com/questions/43297/nt ... s-in-linux

This is almost certainly going to cause problems with ZoneMinder.
You will have to dig into your logs, during the time of the failure, to find out what happened.

If ZoneMinder has any problem reading or writing an event to disk, even for a split second, it will flag the event(s) as orphans, which will cause them to be deleted. If the filesystem doesn't mount on bootup for any reason (if it is dirty for example), ZoneMinder will mark all your events as orphans and will delete them.

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 1:46 pm
by martyouel
Thanks for your answer.

Sounds good...

As it's a dedicated drive for ZM, i'll format it in a linux native filesystem format.

thanks again for your time

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 4:20 pm
by knight-of-ni
Once you've got your disk formatted to a Linux-friendly filesystem like ext4, there are some other design considerations you may want to take, to better ensure you don't lose your events.

- Get a small ups. The size of the ups does not matter, but it must be monitor-able. Install Nut to monitor the ups. This will ensure your system will cleanly shutdown in the event of a power outage.
- If you are running a distro on your Pi which uses systemd (like Fedora), then you should consider using systemd to mount your external drive rather than fstab. If you do that, then it becomes very easy to prevent ZoneMinder from starting on boot-up if the drive does not mount for some reason. Simply create a custom ZoneMinder unit file with the additional parameters "After=extdrive.mount" and "Requires=extdrive.mount". This assumes you've created a mount target called "extdrive.mount". See this for more information about mounting filesystems with systemd: http://unix.stackexchange.com/questions ... -archlinux
- At this point, you still aren't completely out of the woods. Since the drive is external, you would still lose all your events if you accidentally unplugged the usb cable, even for a split second (happens to the best of us... that cable you thought was the mouse cable, wasn't). To combat that and other issues involving data loss, you should schedule regular backups of your mysql database. There is a script I posted in this forum which will backup all your mysql databases, auto-gzip them, and delete old backups > 30 days old.

Whether or not you want to do all this will come down to how important your events are to you.

Re: Events has been purged after power outage

Posted: Thu Feb 25, 2016 7:24 pm
by mikb
knnniggett wrote: - Get a small ups.
...
you would still lose all your events if you accidentally unplugged the usb cable, even for a split second
+1 on the UPS suggestion ...

And another consideration, from experience, even with a UPS, you can get USB interruptions due to the power disturbance, as the power goes out/comes back. This could cause a USB drive to disappear and reappear at a new "drive letter" (/dev/sdc -> /dev/sdd) or other interesting surprises.

Re: Events has been purged after power outage

Posted: Fri Feb 26, 2016 5:12 pm
by martyouel
thanks a lot for all your suggestion

i'll put that in place :)