Backup Zone Changnes

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
Posts: 8
Joined: Mon Jan 07, 2019 2:46 pm

Backup Zone Changnes

Post by vajonam » Fri Nov 06, 2020 3:05 pm

Since there isn't a undo or history functionality to roll back changes to a zone. I have created a quick solution that uses bash/mysqldump and git to periodically check the zones and if there a changes it gets committed to a local git repo that can then be pushed up to an origin.

This way you can undo changes to zones if you are doing some tweaking or some large scale changes that causes too many triggers or not enough.

Code: Select all


VERSION=`mysql -u${USER} -p${PASS} -h${HOST} ${DB} < scripts/version.sql | grep -v Value`
mysqldump -u${USER} -p${PASS} -h${HOST} ${DB} Zones | sed 's$VALUES ($VALUES\n($g' | sed 's$),($),\n($g'| grep -v "Dump completed on"   > zones/Zones_$VERSION.sql
DATE=`date +"%d-%m-%Y %H:%M"`
MESSAGE="zones updated at ${DATE}"
git add zones/*
git commit -am "$MESSAGE"
git push

How it works
  • Get version number of the zoneminder database. e.g: 1.35.10
  • dump the zones table to folder called zones and name it Zones_1.35.10.sql
  • commit the changes to a local git repository
  • push the changes up a remote repo
Run this script however often you need to, it will only commit the changes if any, I run it every 2 hours when I am actively messing with the zones, then I roll it back to once a day.

If you ever want to roll it back you can download the the .sql for date and load it back into the database. restart zm to pickup the changes.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests