Skip to content

Backing up the Watcher database

A PostgreSQL backup preserves Watcher data. Create one before an upgrade, server migration or configuration change. Test restoration in a separate database: the existence of a file alone does not prove it can be restored.

The database backup excludes video archives on disk and server configuration files. Back them up separately. Complete restoration requires compatible package versions, Watcher and Central configuration, and access to the previous archive storage.

The commands below are for a Linux package installation and run as root. The script reads DB from /etc/watcher/watcher.conf. It uses PostgreSQL client utilities; install a compatible postgresql-client if they are missing.

Create a backup

The supplied script:

/opt/flussonic/bin/watcher-backup.sh create

You can also use /opt/flussonic/contrib/watcher backup create. The script creates a PostgreSQL custom-format dump with additional gzip compression. By default it appears in /var/lib/flussonic-watcher/backups/ as watcher_dump_YYYYMMDD_HHMMSS.bak.gz.

After the success message, check the selected file:

gzip -t /var/lib/flussonic-watcher/backups/watcher_dump_20261103_050000.bak.gz
gzip -dc /var/lib/flussonic-watcher/backups/watcher_dump_20261103_050000.bak.gz \
  | pg_restore --list > /var/lib/flussonic-watcher/backups/restore-list.txt

Replace the filename with the actual one. The first command checks the compressed file; the second checks the dump structure. The final test is restoring to a separate test database and reading application data.

Creation uses pg_dump and does not stop Watcher services. Before a migration that must retain the latest changes, make the final backup after stopping changes on the old server.

Restore a backup

Restoration replaces all data in the target database. The script stops Watcher and Central services, clears user schemas and loads the dump. It is intended for a package installation's local PostgreSQL: database existence is checked as the system user postgres.

First place the file in the backup directory, verify it and confirm that DB points to the intended target database. Then specify the filename explicitly:

/opt/flussonic/bin/watcher-backup.sh restore watcher_dump_20261103_050000.bak.gz

The file is looked up inside /var/lib/flussonic-watcher/backups/. The script displays the selected backup and asks for confirmation with y. Without a filename it chooses the newest file in that directory; use an explicit filename for migration or rollback.

On success, Restore success! appears and services start. On restoration failure, services remain stopped. Save the output, fix the cause and repeat restoration from a verified backup; do not start the application on a partially restored database.

After restoration, check:

  • Accounts and organizations — login and access for a test user.
  • Cameras — saved settings and streamer connectivity.
  • Archive — playback of a previously recorded interval from accessible storage.
  • Service state — no startup or database connection errors.

This procedure differs from a database schema upgrade: the package installer runs migrations for the installed version. Match the backup version to the application version before startup.

Example backup schedule

Create a root job in /etc/cron.d/watcher-backup:

0 5 * * * root /opt/flussonic/bin/watcher-backup.sh create >> /var/log/watcher-backup.log 2>&1

It creates a backup daily at 05:00 server time. Check the timezone with timedatectl and ensure cron is running. Monitor job results and free space: this script does not automatically remove old backups on a schedule.

Restrict access to the backup directory and log: the database contains user data. Check both job execution and the existence of a verified file for the required date.

Copy backups to an external server

Keep backups separate from the production database and system disk. Arrange transfer to your backup storage and define retention. Check checksums after transfer and periodically test restoration.

Separately preserve /etc/watcher, /etc/central and, on nodes with watcher-streamer, /etc/flussonic. Protect them against unauthorized access. Video archives require a separate backup process and are not included in the SQL dump.