// to display images directly on GitHub
ifdef::env-github[]
:encoding: UTF-8
:lang: en
:doctype: book
:toc: left
:imagesdir: ../images
endif::[]

////

    This file is part of the PacketFence project.

    See PacketFence_Installation_Guide.asciidoc
    for authors, copyright and license information.

////

//== Export/Import mechanism

This section covers export/import mechanism available since PacketFence 11.0.0.
It can be used to automate parts of upgrades or to restore PacketFence installations.

=== Assumptions and limitations

* You can export on any PacketFence version above 10.3.0
* You can import on any PacketFence version above 11.0.0
* The import process needs to be done on a **standalone** server. Restoring directly to clusters is currently unsupported
** NOTE: Once you restored to your standalone server, you can make it a
    cluster by joining other machines to it and creating your
    [filename]`cluster.conf` but this is relatively advanced and out of scope
    of this document
* Restoring on a fresh install of PacketFence is recommended although
   restoring on an existing instance can work but your milleage may vary
* The import process will not modify network cards configuration of your server: it will
   only update PacketFence IP configuration. We recommend you to define targeted IP
   addresses on network cards before running import process even if you can do it at end of import process.
* The import process will not join automatically server to Active Directory domains. You need to rejoin server manually.
* The import process will only restore the files that can be edited via the admin interface which include:
** Standard configuration files in [filename]`/usr/local/pf/conf/*.conf`
** Connection profiles HTML templates in [filename]`/usr/local/pf/html/captive-portal/profile-templates/`
** Standard certificates
*** [filename]`/usr/local/pf/conf/ssl/*`
*** [filename]`/usr/local/pf/raddb/certs/*`
* Here is a short list of the configuration files that will not be restored. Changes to these files need to be migrated manually. This list is not meant to be complete:
** [filename]`/usr/local/pf/conf/radiusd/*`
** [filename]`/usr/local/pf/conf/log.conf`
** [filename]`/usr/local/pf/conf/log.conf.d/*`
** [filename]`/usr/local/pf/conf/iptables.conf` (but [filename]`/usr/local/pf/conf/iptables-input*.conf.inc` and [filename]`/usr/local/pf/conf/ip6tables-input-management.conf.inc` are restored)
** [filename]`/usr/local/pf/conf/cluster.conf`


WARNING: The import process will never replace a virtual IP address in
configurations. If your export has been done on a cluster, ensure there is no references to
virtual IP address of this cluster after import has been completed.

=== Export on current installation

NOTE: When you are in a cluster, you need to perform this process on the first
member of the incoming addresses of your database cluster. To find the member,
run `show status like 'wsrep_incoming_addresses';` inside your MariaDB
instance and the first IP will be the one where you need to perform the export
process.

==== Installation (for PacketFence version 10.3.0 only)

On PacketFence version 10.3.0, you need to install `packetfence-export` package using following instructions:

.RHEL / CentOS based systems **only**
// subs=attributes allow to substitute {release_minor} in code block
[source,bash,subs="attributes"]
----
yum localinstall http://packetfence.org/downloads/PacketFence/RHEL8/packetfence-export-{release_minor}.el8.noarch.rpm
----

.Debian 9 systems **only**
[source,bash,subs="attributes"]
----
wget http://packetfence.org/downloads/PacketFence/debian/packetfence-export_{release_minor}.deb
dpkg -i packetfence-export_{release_minor}.deb
----

==== Start the export process

The export process will try to use files created by the nightly backup done at
00:30am everyday. If this fine for you and you don't need the latest data,
then you can skip this step. Otherwise to have the latest data and
configuration in your export, run:

[source,bash]
----
/usr/local/pf/addons/backup-and-maintenance.sh
----

Next, run the export script:

[source,bash]
----
/usr/local/pf/addons/full-import/export.sh /tmp/export.tgz
----

The command above will create your export archive in [filename]`/tmp/export.tgz`. You will
now need to copy this file to your new server using SCP or your prefered
mechanism.

=== Import on new installation

You first need to have a PacketFence installation with latest version done on
a standalone server following the instructions in our install guide. You don't
need to go through the configurator unless you want to modify IP settings of
the server.

WARNING: If you want to use the first step of the configurator to configure your
server, you need to do it **before** running your import.

==== Note on Mariabackup

The import script could try to install Mariabackup to import your database dump. If that is the case,
it will remove it at end of import.

Consequently, if you installed Mariabackup **before** running
the import script, you should ensure that Mariabackup is still installed at end of import.

==== Start the import process

The import script will guide you through the restore of the database, the configuration files and will help adjust the PacketFence IP configuration if necessary.

To start the import process using the export archive you made on the current installation:

[source,bash]
----
/usr/local/pf/addons/full-import/import.sh -f /tmp/export.tgz
----

Once the process is completed, you should see the following:

----
Completed import of the database and the configuration! Complete any necessary adjustments and restart PacketFence
----

If that's not the case, check the output above to understand why the process failed.

If you experience any issues during import, you can run it again.

If all goes well, you can restart services using <<PacketFence_Upgrade_Guide.asciidoc#_restart_all_packetfence_services,following instructions>>.

===== Additional steps to build or rebuild a cluster

If you want to build or rebuild a cluster, you need to follow instructions in <<PacketFence_Clustering_Guide.asciidoc#_cluster_setup,Cluster setup section>>.

If your previous installation was a cluster, some steps may not be necessary
to do.  Your export archive will contain your previous
[filename]`cluster.conf` file.

WARNING: if you installed Mariabackup before running the import, it's possible that you need to reinstall it.
