fix(backup): reapply DB triggers on import and carry them in the exportable backup#9136
Conversation
536bcdb to
f586ff3
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a database restore/import failure mode where restores performed from a pf-user mysqldump lose all DB triggers (because the dump contains none), leading to broken cleanup behavior (e.g., orphaned password rows after deleting a user). The fix re-applies trigger definitions from the version-matching PacketFence schema after loading a trigger-less dump, and adds a Venom acceptance test suite to ensure triggers survive restore.
Changes:
- Update
import_mysqldumpto detect trigger-less dumps and reapply triggers (only) frompf-schema-<major>.<minor>.sql. - Add Venom tests validating trigger presence and verifying that deleting a
personremoves the correspondingpasswordrow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
addons/functions/database.functions |
Reapplies trigger definitions from the schema after importing a trigger-less mysqldump. |
t/venom/test_suites/backup_db_and_restore/15_backup_db_and_restore.yml |
Adds acceptance checks ensuring triggers exist post-restore and that the password cleanup trigger works. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
A pf-user mysqldump omits triggers (the pf DB user lacks the TRIGGER privilege), so a restored/imported database loses password_delete_trigger and the ip4log/ip6log/locationlog history triggers. Reapply only the triggers from the matching schema after loading the dump, leaving restored rows untouched.
The base pf-user dump already carries routines (--opt --routines) and PacketFence defines no DB events, so re-dumping them only produced duplicate/no-op objects on restore.
…as-is pf-user dumps omit triggers, so reapply them (from triggers.sql or the matching schema) before any upgrade instead of only for --db-restore. Under --restore-as-is, skip mysql_upgrade and the credential prompt (socket auth).
--restore-as-is restores a same-version backup verbatim: no database/MariaDB/config upgrade, keeps the backup's DB host/port, and asks nothing. Also renames --skip-adjust-conf to --skip-adjust-db-conf since it only adjusts the DB host/port.
Verify config restoration with a marker file and that triggers/routines survive; all restores now use --restore-as-is.
import.sh isolates to packetfence-base and leaves the restart to the operator; the suites now do it via pfcmd service pf start before hitting the webadmin API.
041129b to
be45534
Compare
cluster.conf is restored verbatim since it joined stored_config_files, leaving the node with the source cluster's interfaces/IPs. Rewrite the local node's sections from the corrected pf.conf (and propagate interface renames to the CLUSTER VIP sections); skipped under --restore-as-is.
log.conf and several non-.conf files are restored but were undocumented or wrongly listed as excluded; also document cluster.conf adjustment and --restore-as-is verbatim behavior.
…r-conf Default import no longer adopts the export's cluster config: the server is left standalone with an empty cluster.conf and the export's copy is saved as cluster.conf.imported. --update-cluster-conf opts into restoring and adjusting it; --restore-as-is keeps the current cluster.conf untouched.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
There is an issue with the ignored table and a restore-as-is where these tables are missing |
…st on restore The nightly dump omits large history tables via --ignore-table, leaving trigger targets (locationlog_history) missing after a restore. Export their structure and recreate them empty on import. Only tables that exist are dumped, so obsolete names (iplog_archive) never break the export.
Backups made before excluded_tables_schema.sql existed don't carry it, so fall back to the matching pf-schema (with the devel X.Y.sql fallback) to recreate the excluded tables empty on restore.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Description
(REQUIRED)
Restoring a PacketFence DB silently dropped all triggers, so the restored
instance stopped cleaning up related rows — most visibly, deleting a user no
longer removed its
passwordrow (re-creating the user then failed with409 Conflict), and theip4log/ip6log/locationloghistory triggers were lost.Root cause:
mysqldumpruns as thepfuser, which lacks theTRIGGERprivilege, so the dump has no triggers. On import the DB is dropped, recreated
and reloaded from that trigger-less dump, and the triggers were never reapplied.
Fix:
import_mysqldumpreapplies triggers when thedump has none — from
triggers.sqlin the export, falling back to the matchingpf-schema-<version>.sql. Idempotent, and runs beforeupgrade_database.export.sh(already root) also dumpstriggers.sql(triggers only). Routines already ride in the base dump; there are no DB events.
--db-restorewith--restore-as-is. A composable non-interactivemodifier (with
--db/--conf/full) that skips upgrades and keeps the backup'svalues.
Impacts
(REQUIRED)
export.shemitstriggers.sqlalongsidegrants.sql.database.functions(import_mysqldump) reapplies triggers when the dump lacksthem.
import.shdrops--db-restore, adds--restore-as-is.Backport
(REQUIRED)
Bug was masked by cross-version upgrades but real for same-version restore, a
standard workflow since
exportable-backup(14.1). Affected: 14.1 → 15.1.Backport to at least maintenance/15.1.
Delete branch after merge
(REQUIRED)
YES
Checklist
(REQUIRED) - [yes, no or n/a]
--help)backup_db_and_restorechecks the exportcarries triggers and that triggers/routines survive the restore, and covers the
--restore-as-isdb/conf/full restores, each restarting PacketFence(
pfcmd service pf start) so the API is reachable after.NEWS file entries
(REQUIRED, but may be optional...)
Bug Fixes
passwordrows after a user is deleted on restored databases
Enhancements
self-contained;
import.shgains--restore-as-isfor non-interactive importsUPGRADE file entries
(OPTIONAL, but may be required...)
Databases restored with older code may be missing triggers. Re-import with the
fixed code, or reapply from
/usr/local/pf/db/pf-schema-<version>.sqlas root.