Back up and restore the database

Back up the Telegraf Controller database regularly, and always before an upgrade, so you can restore the server to a known-good state.

Database backups contain user records, hashed credentials, API tokens, and session data. Store backup files with the same care as the live database.

SQLite

Back up SQLite

How you back up SQLite depends on whether Telegraf Controller is running.

While Telegraf Controller is running

Use the SQLite .backup command, which produces a consistent copy of a live database:

sqlite3 /path/to/sqlite.db ".backup '/path/to/backups/sqlite-backup.db'"

Replace /path/to/sqlite.db with your database location. For default locations, see Default SQLite data locations.

Never copy a live database file with cp or a file manager. While Telegraf Controller is running, part of the database state lives in the -wal companion file, and a plain copy taken mid-write produces a corrupt backup.

The .backup command requires the SQLite command-line shell. For installation instructions, see SQLite CLI prerequisites.

While Telegraf Controller is stopped

With the server stopped, the database is a regular file. Copy the database file and, if present, its -wal and -shm companion files:

cp /path/to/sqlite.db /path/to/sqlite.db-wal /path/to/sqlite.db-shm /path/to/backups/

Restore SQLite

  1. Stop Telegraf Controller.

  2. Move the current database file and any -wal and -shm companion files out of the way:

    mkdir -p /path/to/old-database
    mv /path/to/sqlite.db* /path/to/old-database/
  3. Copy the backup file to the configured database path:

    cp /path/to/backups/sqlite-backup.db /path/to/sqlite.db
  4. Start Telegraf Controller and verify that the web interface loads and your configurations and agents are present.

PostgreSQL

For PostgreSQL, use standard PostgreSQL tooling or your provider’s backup features.

Back up PostgreSQL

pg_dump --dbname=telegraf_controller --file=telegraf_controller.sql

Restore PostgreSQL

psql --dbname=telegraf_controller --file=telegraf_controller.sql

Back up and restore audit log files

If you use audit logging, Telegraf Controller writes audit records to per-month SQLite files, separate from the application database. Audit log files are SQLite databases even if the application database is PostgreSQL. Restoring an application database backup does not restore audit logs.

Follow the same SQLite backup and restore procedures for each audit log file. For default audit log file locations, see Where audit logs are stored.

In a high-availability Telegraf Controller cluster, each node writes its own audit log files. Back up the audit log files on every node. See Audit logs in a cluster.


Was this page helpful?

Thank you for your feedback!