Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
da76837
fix(import): reapply triggers from schema on import
JeGoi Jun 30, 2026
a7163f3
test(venom): verify DB triggers survive restore in backup_db_and_restore
JeGoi Jun 30, 2026
650a45e
fix(backup): export only triggers, not routines or events
JeGoi Jul 6, 2026
dd52277
fix(import): reapply DB triggers on every import and honor --restore-…
JeGoi Jul 6, 2026
9b0000c
feat(import): replace --db-restore with non-interactive --restore-as-is
JeGoi Jul 6, 2026
a60075c
docs(import): document import.sh options
JeGoi Jul 6, 2026
e5c183b
test(venom): cover --restore-as-is db/conf/full restores
JeGoi Jul 6, 2026
be45534
test(venom): restart PacketFence after import so API is reachable
JeGoi Jul 6, 2026
75c9320
feat(import): adjust restored cluster.conf for the local node
JeGoi Jul 6, 2026
f244116
docs(import): correct restored-files list and cluster.conf handling
JeGoi Jul 6, 2026
923a2ab
feat(import): keep cluster.conf empty by default, add --update-cluste…
JeGoi Jul 6, 2026
d68a7af
docs(import): document cluster.conf default and --update-cluster-conf
JeGoi Jul 6, 2026
fc4aa36
Potential fix for pull request finding
JeGoi Jul 7, 2026
b9f676a
Potential fix for pull request finding
JeGoi Jul 7, 2026
5abaca1
Potential fix for pull request finding
JeGoi Jul 7, 2026
71b3081
fix(import): export excluded tables' structure so trigger targets exi…
JeGoi Jul 7, 2026
beb58a3
fix(import): recreate excluded tables from schema for old backups
JeGoi Jul 7, 2026
e3ce7fb
test(venom): verify all schema tables and excluded table present afte…
JeGoi Jul 7, 2026
6dbdda7
Potential fix for pull request finding
satkunas Jul 7, 2026
0167d0a
Potential fix for pull request finding
satkunas Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions addons/full-import/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,35 @@ if echo "$last_db_dump" | grep '\.sql.gz$' >/dev/null; then
mariadb_args="$mariadb_args -p$mariadb_root_pass"
fi

db_name=$(/usr/local/pf/bin/get_pf_conf database db)
db_name=${db_name:-pf}

echo "Database dump uses mysqldump. Exporting the grants from the database. Enter the MariaDB root password if prompted to"
mysql $mariadb_args --skip-column-names -A -e"SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user WHERE user<>'' AND user<>'PUBLIC'" | mysql $mariadb_args --skip-column-names -A | sed 's/$/;/g' > grants.sql

# pf-user dump omits triggers (no TRIGGER privilege); dump them as root.
# Routines are skipped: the base pf dump already carries them.
echo "Exporting the triggers from the database"
mysqldump $mariadb_args --single-transaction --no-create-info --no-data --skip-add-drop-table \
--triggers "$db_name" > triggers.sql

# The nightly dump omits large history tables via --ignore-table, but triggers
# write to them (e.g. the locationlog trigger inserts into locationlog_history),
# so export their structure only to recreate the empty tables on import.
# Keep this list in sync with the --ignore-table list in backup-and-maintenance.sh;
# only tables that exist are dumped, so obsolete names (pre-10.3) are ignored.
excluded_tables="locationlog_history iplog_archive"
existing_excluded=""
for t in $excluded_tables; do
if [ -n "$(mysql $mariadb_args -N -B -e "SHOW TABLES LIKE '$t'" "$db_name" 2>/dev/null)" ]; then
existing_excluded="$existing_excluded $t"
fi
done
if [ -n "$existing_excluded" ]; then
echo "Exporting the structure of the tables excluded from the dump:$existing_excluded"
mysqldump $mariadb_args --no-data --skip-triggers --skip-add-drop-table \
"$db_name" $existing_excluded > excluded_tables_schema.sql
fi
fi

main_splitter
Expand Down
107 changes: 61 additions & 46 deletions addons/full-import/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import_db() {
if echo "$db_dump" | grep '\.sql$' >/dev/null; then
echo "The database dump uses mysqldump"
#TODO /tmp/grants.sql should be included in the export
import_mysqldump grants.sql $db_dump usr/local/pf/conf/pf.conf $do_db_restore
import_mysqldump grants.sql $db_dump usr/local/pf/conf/pf.conf
elif echo "$db_dump" | grep '\.xbstream$' >/dev/null; then
echo "The database uses mariabackup"
# permit to remove mariabackup if everything goes well
Expand All @@ -96,7 +96,10 @@ import_db() {
exit 1
fi

if [ "$do_db_restore" -eq 0 ] ; then
if [ "$do_restore_as_is" -eq 1 ]; then
main_splitter
echo "--restore-as-is: same version, skipping database upgrade"
else
handle_devel_upgrade `egrep -o '[0-9]+\.[0-9]+\.[0-9]+$' /usr/local/pf/conf/pf-release | egrep -o '^[0-9]+\.[0-9]+'`

#TODO: check the version of the export, we want to support only 10.3.0 and above
Expand All @@ -105,9 +108,6 @@ import_db() {
main_splitter
db_name=`get_db_name usr/local/pf/conf/pf.conf`
upgrade_database $db_name
else
main_splitter
echo "Only database restoration has been selected. No upgrade on database will be done"
fi
}

Expand All @@ -118,14 +118,21 @@ import_config() {
main_splitter
handle_network_change

main_splitter
handle_cluster_conf_restore `pwd`

main_splitter
restore_profile_templates

main_splitter
upgrade_imported_configuration
if [ "$do_restore_as_is" -eq 1 ]; then
echo "--restore-as-is: same version, skipping configuration upgrade"
else
upgrade_imported_configuration
fi

main_splitter
if [ "$do_adjust_config" -eq 1 ]; then
if [ "$do_adjust_db_conf" -eq 1 ]; then
echo "Performing adjustments on the configuration"
adjust_configuration
else
Expand All @@ -139,42 +146,39 @@ import_config() {


finalize_import() {
if [ "$do_db_restore" -eq 0 ] ; then
main_splitter
echo "Finalizing import"
main_splitter
echo "Finalizing import"

sub_splitter
echo "Applying fixpermissions"
/usr/local/pf/bin/pfcmd fixpermissions
sub_splitter
echo "Applying fixpermissions"
/usr/local/pf/bin/pfcmd fixpermissions

sub_splitter
echo "Restarting packetfence-redis-cache"
systemctl restart packetfence-redis-cache
sub_splitter
echo "Restarting packetfence-redis-cache"
systemctl restart packetfence-redis-cache

sub_splitter
echo "Restarting packetfence-config"
systemctl restart packetfence-config
sub_splitter
echo "Restarting packetfence-config"
systemctl restart packetfence-config

sub_splitter
echo "Reloading configuration"
configreload
sub_splitter
echo "Reloading configuration"
configreload

main_splitter
main_splitter
if [ "$do_full_import" -eq 1 ]; then
echo "Completed import of the database and the configuration! Complete any necessary adjustments and restart PacketFence"

# Done with everything, time to cleanup!
systemctl cat monit > /dev/null 2>&1 && systemctl enable monit
else
main_splitter
echo "Finalizing db restoration"

sub_splitter
echo "Restarting service packetfence-httpd.admin_dispatcher"
systemctl restart packetfence-httpd.admin_dispatcher
echo "Restarting packetfence-haproxy-admin service"
systemctl start packetfence-haproxy-admin
elif [ "$do_db_import" -eq 1 ]; then
echo "Completed import of the database! Complete any necessary adjustments and restart PacketFence"
elif [ "$do_config_import" -eq 1 ]; then
echo "Completed import of the configuration! Complete any necessary adjustments and restart PacketFence"
else
echo "Completed import! Complete any necessary adjustments and restart PacketFence"
fi

# Done with everything, time to cleanup!
systemctl cat monit > /dev/null 2>&1 && systemctl enable monit

popd > /dev/null
}

Expand All @@ -188,9 +192,10 @@ Options:
-f,--file Import a PacketFence export (mandatory)
-h,--help Display this help
--db Import only database from PacketFence export
--db-restore Restore only database from PacketFence export without upgrade process
--conf Import only configuration from PacketFence export
--skip-adjust-conf Don't run adjustments on configuration (only use it if you know what you are doing)
--skip-adjust-db-conf Config import only: keep the backup's DB host/port instead of forcing localhost
--restore-as-is Reapply the backup exactly: same version (no upgrade), keep its DB host/port, no prompts
--update-cluster-conf Restore the export's cluster.conf and adjust it for this server (default: keep cluster.conf empty)

EOF
}
Expand All @@ -200,16 +205,17 @@ EOF
#############################################################################
do_full_import=1
do_db_import=0
do_db_restore=0
do_config_import=0
do_adjust_config=1
do_adjust_db_conf=1
do_restore_as_is=0
do_update_cluster_conf=0
mariabackup_installed=false
EXPORT_FILE=${EXPORT_FILE:-}

# Parse option
# TEMP=$(getopt -o f:h --long file:,help,db,conf \
# -n "$0" -- "$@") || (echo "getopt failed." && exit 1)
TEMP=$(getopt -o f:h --long file:,help,db,db-restore,conf,skip-adjust-conf \
TEMP=$(getopt -o f:h --long file:,help,db,conf,skip-adjust-db-conf,restore-as-is,update-cluster-conf \
-n "$0" -- "$@") || (echo "getopt failed." && exit 1)

# Note the quotes around `$TEMP': they are essential!
Expand All @@ -226,16 +232,19 @@ while true ; do
help ; exit 0 ; shift
;;
--db)
do_db_restore=0 ; do_db_import=1 ; do_full_import=0 ; shift
;;
--db-restore)
do_db_restore=1 ; do_db_import=1 ; do_full_import=0 ; shift
do_db_import=1 ; do_full_import=0 ; shift
;;
--conf)
do_config_import=1 ; do_full_import=0 ; shift
;;
--skip-adjust-conf)
do_adjust_config=0 ; shift
--skip-adjust-db-conf)
do_adjust_db_conf=0 ; shift
;;
--restore-as-is)
do_restore_as_is=1 ; shift
;;
--update-cluster-conf)
do_update_cluster_conf=1 ; shift
;;
--)
shift ; break
Expand All @@ -257,6 +266,12 @@ if [ ! -f "$EXPORT_FILE" ]; then
exit 1
fi

# --restore-as-is reapplies the backup verbatim, so it also keeps the backup's
# DB host/port (skips adjust_configuration) like --skip-adjust-db-conf does.
if [ "$do_restore_as_is" -eq 1 ]; then
do_adjust_db_conf=0
fi

#############################################################################
### Import process
#############################################################################
Expand Down
Loading
Loading