Skip to content

Database & Backups

CoreSight uses an encrypted SQLite database (via SQLCipher) stored locally in /opt/coresight/server/data/coresight.db.

Lost or Invalid Encryption Key

Error: SQLITE_NOTADB: file is not a database

This error indicates that the SQLite engine cannot decrypt the file. This happens systematically if the DB_ENCRYPTION_KEY encryption key does not match the one used when creating the database.

Diagnostics and Solution:

  1. Check the environment file: cat /opt/coresight/server/.env
  2. If you restored an old database without restoring the corresponding .env file, you must find the original key.
  3. Important: The key cannot be recalculated. If you permanently lose the key, the data is unrecoverable.

Database Corruption

Although rare thanks to the WAL (Write-Ahead Logging) mode, a sudden power failure during a disk write can corrupt the file.

How to check integrity (PRAGMA integrity_check)

bash
sudo /opt/coresight/node/bin/node -e "
const Database = require('/opt/coresight/server/node_modules/better-sqlite3-multiple-ciphers');
const key = require('fs').readFileSync('/opt/coresight/server/.env', 'utf8').match(/DB_ENCRYPTION_KEY=(.+)/)[1].trim();
const db = new Database('/opt/coresight/server/data/coresight.db');
db.pragma('key=\'' + key + '\'');
const result = db.pragma('integrity_check');
console.log(result);
db.close();
"

If the result shows "ok", the database is not corrupted. Otherwise, you must restore a backup.

Restoring a Backup

The installation/update process automatically creates backups in the /opt/coresight/backups/ folder.

Full restore procedure:

bash
# 1. Stop the service
sudo systemctl stop coresight

# 2. Rename the current database (as a precaution)
sudo mv /opt/coresight/server/data/coresight.db /opt/coresight/server/data/coresight.db.broken

# 3. Copy the desired backup
sudo cp /opt/coresight/backups/coresight_1.1.0_20260623_120000.db /opt/coresight/server/data/coresight.db

# 4. Ensure correct permissions
sudo chown coresight:coresight /opt/coresight/server/data/coresight.db

# 5. Restart
sudo systemctl start coresight

CoreSight Documentation