Airflow db restore completes but no built-in check confirms recovered metadata matches the backup
0 reputation · 19 Mar 2022, 05:45 UTC
0 reputation · 19 Mar 2022, 05:45 UTC
Apache Airflow ships airflow db backup and airflow db restore to export and reimport the metadata database (PostgreSQL, MySQL, or SQLite) for disaster recovery. The restore command finishes without error, but there is no documented validation step that compares the restored database against the backup file itself — no row-count or checksum comparison is built in.
The constraints here are practical. The metadata DB holds DAGs, connections, variables, and task instance history, but the Fernet key, task logs, plugins, and custom Python dependencies live outside it, so a clean restore does not prove the environment is whole. Application-level checks such as airflow db check and airflow dags list confirm connectivity and presence, yet they do not establish completeness against what was captured. Version alignment between the backup source and restore target also matters, since schema differences can silently change what gets recovered. Assume Airflow 2.x with a PostgreSQL backend.
Given this, what is a defensible verification strategy after airflow db restore?
dag, connection, variable, task_instance) are the minimum set worth row-count or checksum comparison between backup and restored database?airflow dags list output be reliably diffed pre- and post-restore, or do serialization and parsing states make that comparison misleading?35775 reputation · 19 Mar 2022, 11:13 UTC
After airflow db restore completes, the safest way to confirm that the restored metadata matches what was captured is to perform a two‑stage check:
Airflow’s backup format is a plain SQL dump of the PostgreSQL schema. The restore command simply feeds that dump back into the database. Because the dump contains only DDL and INSERT statements, there is no built‑in checksum. The absence of a verification step is a known limitation; most teams rely on manual row‑count or application‑level checks.
dag, connection, variable, and task_instance tables hold the core orchestration state.airflow db check after the restore ensures the schema is compatible with the Airflow binary.variable table; decryption fails if the Fernet key has changed.psql -U airflow -d temp_restore -f backup.sql
SELECT tablename, COUNT(*) FROM pg_tables WHERE schemaname='public' GROUP BY tablename;
psql -U airflow -d airflow
SELECT 'dag' AS table_name, COUNT(*) AS rows FROM dag
UNION ALL
SELECT 'connection', COUNT(*) FROM connection
UNION ALL
SELECT 'variable', COUNT(*) FROM variable
UNION ALL
SELECT 'task_instance', COUNT(*) FROM task_instance;
Compare each count to the baseline. A mismatch indicates incomplete restoration or a schema drift.
airflow db check
airflow dags list
The first command verifies the schema version; the second confirms the DAG processor can read the dag table.
my_secret).airflow variables get my_secret
If the command prints the plaintext, the key matches; if it prints an error or garbled text, the key is wrong.
airflow dags list output. Capture the output before restore (e.g., airflow dags list > dags_before.txt) and after restore (airflow dags list > dags_after.txt). A simple diff will show missing or altered DAG definitions. Note that the list reflects the current DAG processor state, so differences may also stem from code changes rather than the restore.
Do you have the exact row counts (or a checksum) of the critical tables from the backup before the restore? Knowing those numbers allows a precise comparison and removes ambiguity in the verification step.
airflow db upgrade after restoring a database that came from an older Airflow release.While Airflow does not ship a checksum validator, a small set of row‑count checks, schema version verification, and a Fernet‑key read test provide a defensible assurance that the restored metadata matches the backup.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.