NetBox Enterprise Backups
Much like the NetBox software itself, NetBox Enterprise uses 2 main datastores: PostgreSQL, and Redis.
PostgreSQL is used for the primary model data in NetBox, including sites, facilities, racks, and so on.
Redis is used for internal caching and the task queue.
For each type of datastore you can choose to use a built-in deployment, or configure NetBox Enterprise to use an existing external resource already in your environment.
External Databases
If you are providing your own database(s) for use by NetBox Enterprise, it is expected that you have your own processes for high availability, backup, and restore.
Using Disaster Recovery for Backups
A disaster recovery backup will preserve the complete state of your NetBox Enterprise install, from allocated volumes to databases to custom configuration.
This feature is included in NetBox Enterprise installs, and can be enabled by installing some extra dependencies to your cluster for KOTS installs.
Backing Up the NetBox Enterprise Installation
- Navigate to the backup configuration by clicking the ^^Backup settings^^ link in the Disaster Recovery section of the admin console.

- Input your S3 bucket, credentials, endpoint, and region.

- Click Update storage settings -- it will spend a few moments validating that your settings work.

- Perform a backup by clicking the Backups tab, and then clicking Start backup.

Restoring the NetBox Enterprise Installation
- Download the latest NetBox Enterprise installer following the same instructions you did for a new install, if you haven't already.
- Run:
./netbox-enterprise restore - Enter the same S3 credentials you use for backups.

- Next, it will take a few minutes to bring up the node.
When it's complete, you will be prompted to continue the restore:

- Enter
Yto continue, and the restore will launch the cluster. - (Optional) If you plan to have more than one node in the new cluster, you can go to the admin console and configure them when prompted.
- Enter
continueto finish bringing the NetBox Enterprise application up.

- It will take a few more minutes to finish bringing the application up, and then you will see "Application restored!"

NetBox Enterprise and the Admin Console should now be completely restored and available as normal.
Manual Backup and Restore
Besides disaster recovery, it is also a good idea to keep backups of your data in case you want to view, partially restore, or move your data to another system.
NetBox Enterprise Namespace
The default namespace is kotsadm.
The instructions below default to kotsadm, but you can change the NETBOX_NAMESPACE variable to match your system.
Backing Up Your Data
Backing up NetBox Enterprise's data manually is reasonably simple, and Kubernetes makes it easy to access them from the command-line.
Before You Back Up: Accessing Your Cluster
Before you can back anything up, you must first make sure you can access the cluster on the command line.
See the advanced tools documentation for details on connecting to your NetBox Enterprise cluster.
Media, Scripts, and Reports
Runtime files are stored in a volume accessible from the NetBox containers. To back them up, you can run this:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_MAIN_POD="$(kubectl get pod \
-o name \
-n "${NETBOX_NAMESPACE}" \
-l 'app.kubernetes.io/component=netbox' \
| head -n 1 \
)" && \
kubectl exec "${NETBOX_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-c netbox \
-- /bin/sh -c ' \
cd /opt/netbox/netbox && \
find media scripts reports static -type f > /tmp/files.txt && \
tar -czf - \
--owner=0 \
--group=0 \
-T /tmp/files.txt' > netbox-data.tar.gzBuilt-In PostgreSQL
The built-in PostgreSQL is deployed using the CrunchyData Postgres Operator.
Since the PostgreSQL CLI tools are already available inside the cluster, all we need to do to dump the database is to call into the correct container and run a pg_dump there.
To perform a database dump, run these commands:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_DATABASE_FILE="netbox-enterprise.pgsql" && \
POSTGRESQL_MAIN_POD="$(kubectl get pod \
-o name \
-n "${NETBOX_NAMESPACE}" \
-l 'postgres-operator.crunchydata.com/role=master' \
| head -n 1 \
)" && \
EXCLUDE_DATABASES="$(kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-c database \
-- \
psql -t -c "SELECT CONCAT('--exclude-database=', datname) \
FROM pg_database \
WHERE datname <> ALL ('{netbox,diode,hydra}')" \
)" && \
kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-c database \
-- \
pg_dumpall \
$EXCLUDE_DATABASES \
> "${NETBOX_DATABASE_FILE}"This will create a netbox-enterprise.pgsql file in your local directory.
Save it somewhere safe for future restores.
For more details on backing up NetBox databases, see the official NetBox documentation.
Diode and Hydra Secrets (NetBox 1.10 and Up)
A manual database restore works only if the rest of the cluster can decrypt the restored data.
The commands below back up the secrets that the restored databases depend on.
The names are for a NetBoxEnterprise resource named netbox, as on Embedded Cluster.
Elsewhere they begin with the name of your resource.
netbox-netbox-config: the NetBoxSECRET_KEYnetbox-netbox-superuser: the generated superuser credentials. It exists only when NetBox Enterprise generates the superuser, so Embedded Cluster does not have it.netbox-diode-hydra-secret: the Hydra system secret, which encrypts the Hydra signing keys in thehydradatabasenetbox-diode-auth-oauth2-secret: the Diode OAuth2 client secrets, which match the clients in thehydradatabase
The commands do not back up the other secrets in the namespace, and you do not need them.
NetBox Enterprise, the PostgreSQL operator, and your license create them again on the target install.
The restore does not change the PostgreSQL user passwords, so the target install keeps its own pguser secrets.
The commands write only the name, labels, type, and data of each secret. They leave out the owner references, which identify the NetBoxEnterprise resource of this install and do not apply to another install.
Run these commands:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_CLUSTER="$(kubectl get netboxenterprise \
-n "${NETBOX_NAMESPACE}" \
-ojsonpath='{.items[0].metadata.name}')" && \
SECRET_TEMPLATE='---
apiVersion: v1
kind: Secret
metadata:
name: {{ .metadata.name }}
labels:
{{- range $key, $value := .metadata.labels }}
{{ $key }}: "{{ $value }}"
{{- end }}
type: {{ .type }}
data:
{{- range $key, $value := .data }}
{{ $key }}: "{{ $value }}"
{{- end }}
' && \
: > netbox-enterprise-secrets.yaml && \
chmod 600 netbox-enterprise-secrets.yaml && \
for SECRET in netbox-config netbox-superuser diode-hydra-secret diode-auth-oauth2-secret; do \
kubectl get secret "${NETBOX_CLUSTER}-${SECRET}" \
--namespace "${NETBOX_NAMESPACE}" \
--ignore-not-found \
-o go-template="${SECRET_TEMPLATE}"; \
done >> netbox-enterprise-secrets.yamlIf the commands print an error, the file can be incomplete: fix the cause and run them again.
If the error is array index out of bounds, they found no NetBoxEnterprise resource in the namespace, and they did not change an earlier file.
Before you store the file, list the secrets in it:
grep '^ name: ' netbox-enterprise-secrets.yamlThe list must include netbox-netbox-config.
If Diode is turned on, it must also include netbox-diode-hydra-secret and netbox-diode-auth-oauth2-secret.
The file holds the secret values, and only your user can read it.
Keep it with your netbox-enterprise.pgsql file for future restores, and protect both as you protect passwords.
Admin Console Configuration
You can export the current Admin Console configuration as a ConfigValues file. This is useful when migrating to a new host or reinstalling, as it captures all your Admin Console settings (database connections, TLS configuration, feature toggles, etc.) in a portable YAML file.
From within the cluster shell, run:
kubectl exec deploy/kotsadm -n kotsadm -- \
/kots get config --current --decrypt --namespace kotsadm \
> netbox-enterprise-config.yamlThe --decrypt flag ensures that password fields (like database credentials) are included in plaintext rather than encrypted. Store this file securely alongside your other backups.
To apply a saved configuration to a new install, run:
kubectl exec -i deploy/kotsadm -n kotsadm -- \
/kots set config netbox-enterprise \
--config-file /dev/stdin --deploy --namespace kotsadm \
< netbox-enterprise-config.yamlRestoring Your Backups
Restoring is almost as simple as backing up. You just need to put NetBox Enterprise into maintenance mode first.
Enabling and Disabling Maintenance Mode
- Put NetBox Enterprise into maintenance mode by going to the Config tab and checking the Enable Maintenance Mode checkbox.

- Click the "Save config" button at the bottom of the form, and then when the admin console prompts you, click "go to updated version".

- Confirm that the New version available at the top denotes it's a config change, and if so click the "Deploy" button.

This will shut down NetBox but leave the other NetBox Enterprise infrastructure up, so you can safely restore.
When you are done restoring your data, just follow the same steps, unchecking Enable Maintenance Mode and deploying the updated configuration.
Media, Scripts, and Reports
To restore media, scripts, and reports, you just need to unpack them into the correct directory inside a NetBox container.
The backup instructions above back up all three of the media/, scripts/, and reports/ subdirectories in one file.
If you are restoring a backup from another NetBox instance, you might need to change the name of the tarball and the path after the -C at the end of this command to unpack your backup into the right location.
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_MAINTENANCE_POD="$(kubectl get pod \
-o name \
-n "${NETBOX_NAMESPACE}" \
-l 'maintenance-mode=true' \
| head -n 1 \
)" && \
cat netbox-data.tar.gz | kubectl exec ${NETBOX_MAINTENANCE_POD} \
-n "${NETBOX_NAMESPACE}" \
-i \
-- tar -xvzf - \
--no-same-owner \
--no-same-permission \
-C /opt/netbox/netboxDiode and Hydra Secrets (NetBox 1.10 and Up)
Restore the secrets before the database dump. NetBox needs them to check sessions, and Hydra needs them to serve Diode OAuth flows against the restored data.
To restore into a new install, first turn on the same features as the install that you backed up, such as Diode, and wait until NetBox Enterprise is ready. NetBox Enterprise then creates each secret, and the restore replaces only its values. If a feature is off on the target, NetBox Enterprise deletes the restored secret of that feature on its next reconcile. When you turn the feature on later, NetBox Enterprise creates a new secret, which does not match the restored data.
The commands apply only the secrets listed in the backup, and only their name, labels, type, and data.
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_CLUSTER="$(kubectl get netboxenterprise \
-n "${NETBOX_NAMESPACE}" \
-ojsonpath='{.items[0].metadata.name}')" && \
SECRET_TEMPLATE='---
apiVersion: v1
kind: Secret
metadata:
name: {{ .metadata.name }}
labels:
{{- range $key, $value := .metadata.labels }}
{{ $key }}: "{{ $value }}"
{{- end }}
type: {{ .type }}
data:
{{- range $key, $value := .data }}
{{ $key }}: "{{ $value }}"
{{- end }}
' && \
for SECRET in netbox-config netbox-superuser diode-hydra-secret diode-auth-oauth2-secret; do \
kubectl create \
--dry-run=client \
--filename netbox-enterprise-secrets.yaml \
-o go-template="{{ if eq .metadata.name \"${NETBOX_CLUSTER}-${SECRET}\" }}${SECRET_TEMPLATE}{{ end }}"; \
done \
| kubectl apply \
--server-side \
--force-conflicts \
--namespace "${NETBOX_NAMESPACE}" \
--filename -The command prints one serverside-applied line for each listed secret in the file.
If it prints fewer lines than that, an error, or no objects passed to apply, stop, and do not restore the database.
A database restored without its secrets cannot be read with the keys of the target install.
no objects passed to apply means that the file holds no secret for the NetBoxEnterprise resource in this namespace.
The NetBoxEnterprise resource on the target must have the same name as the one that you backed up.
Then restart the pods that use the old secret values, so that they get the restored credentials:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
kubectl rollout restart deployment \
--namespace "${NETBOX_NAMESPACE}" \
-l 'app.kubernetes.io/managed-by=netbox-operator'Built-In PostgreSQL
To restore from a dump file, pipe the netbox-enterprise.pgsql created during backup into psql in the PostgreSQL pod:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
NETBOX_DATABASE_FILE="netbox-enterprise.pgsql" && \
DIODE_DEPLOYMENT_COUNT="$(kubectl get deployments -n "${NETBOX_NAMESPACE}" -o name | grep -c diode || :)" && \
HYDRA_DEPLOYMENT_COUNT="$(kubectl get deployments -n "${NETBOX_NAMESPACE}" -o name | grep -c hydra || :)" && \
POSTGRESQL_MAIN_POD="$(kubectl get pod \
-o name \
-n "${NETBOX_NAMESPACE}" \
-l 'postgres-operator.crunchydata.com/role=master' \
| head -n 1 \
)" && \
for DB in netbox diode hydra; do
kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-c database \
-- dropdb --if-exists --force "${DB}"; \
done && \
( \
if [ "${DIODE_DEPLOYMENT_COUNT}" -gt 0 ]; then \
echo "CREATE DATABASE diode WITH TEMPLATE = template0 ENCODING = 'UTF8';"; \
fi && \
if [ "${HYDRA_DEPLOYMENT_COUNT}" -gt 0 ]; then \
echo "CREATE DATABASE hydra WITH TEMPLATE = template0 ENCODING = 'UTF8';"; \
fi && \
echo "CREATE DATABASE netbox WITH TEMPLATE = template0 ENCODING = 'UTF8';"; \
) \
| kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-i \
-c database \
-- psql -d template1 -f- && \
grep -v -E '^(ALTER|CREATE|DROP) (DATABASE|ROLE) ' "${NETBOX_DATABASE_FILE}" \
| kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-i \
-c database \
-- psql -d netbox -f-Following this run the below to ensure all database permissions are correct:
NETBOX_NAMESPACE="$(kubectl get deployments \
-A -l 'app.kubernetes.io/component=netbox' \
-ojsonpath='{.items[0].metadata.namespace}')" && \
POSTGRESQL_MAIN_POD="$(kubectl get pod \
-o name \
-n "${NETBOX_NAMESPACE}" \
-l 'postgres-operator.crunchydata.com/role=master' \
| head -n 1 \
)" && \
for DB in $(kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-c database \
-- \
psql -t -c "SELECT datname FROM pg_database WHERE datname IN ('netbox', 'hydra', 'diode');"; \
); do \
kubectl exec "${POSTGRESQL_MAIN_POD}" \
-n "${NETBOX_NAMESPACE}" \
-i \
-c database \
-- \
psql --dbname "${DB}" -e -c "\
ALTER DATABASE ${DB} OWNER TO ${DB}; \
GRANT ALL PRIVILEGES ON DATABASE ${DB} TO ${DB}; \
GRANT CREATE ON SCHEMA public TO ${DB}; \
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO ${DB}; \
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO ${DB}; \
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ${DB}; \
"; \
done