How do I back up the built in EventSentry database?

Article ID: 235
Category: Database
Applies to: 2.93+
Updated: 2024-05-01

If you are using the built in EventSentry database, you can back it up using the "pg_dump.exe" utility. This is located by default in the EventSentry\postgresql14\bin folder.

You can create a batch file with the following contents:

SET PGPASSWORD=your_postgres_account_password
"C:\Program Files\EventSentry\postgresql14\bin\pg_dump.exe" -h localhost -p 5432 -U postgres -F c -b -v -f "C:\backups\es_database.backup" EventSentry

Please note: If you still use Postgres 9.6, pgdump.exe will be in the "C:\Program Files (x86)\EventSentry\postgresql96\bin" folder instead. Also consider the C:\backups\ path in the script is an example, you should change to a path that exists on your server with enough free space for the backup. Lastly, the word "EventSentry" at the end of the script is a placeholder for the name of your database. To check what your database name is, you can open the EventSentry console to Actions > Primary Database, click the "create" button, and see the database name and port.

Right-click the batch file and choose Run As Administrator, and this will dump the entire database into a file that can be restored. The .backup file it produces can be backed up with your regular backup software as well.

Please see the reference link at the bottom of this article for more information regarding how to make this more automated.

To restore the database from a backup, run these commands from the command prompt after opening the command prompt using Run As Administrator:

"C:\Program Files\EventSentry\postgresql14\bin\psql.exe" -U postgres -c "CREATE DATABASE \"EventSentry\""
"C:\Program Files\EventSentry\postgresql14\bin\pg_restore.exe" -h localhost -U postgres -d EventSentry -v c:\backups\es_database.backup

*Please note: If you still use Postgres 9.6, psql.exe and pg_restore.exe will be in the "C:\Program Files (x86)\EventSentry\postgresql96\bin" folder instead