From 20f36ae46db7606ed9d7b6dacf5dc1a1048624b9 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 13:30:18 -0400 Subject: [PATCH 1/7] update documentation to match backup/restore workflow for 1.3.0 * disable S3 backup for now (we're not starting S3 in 1.3.0) * add manual backup instructions for archiving the media/scripts/reports directories to a tarball * add manual restore instructions for unpacking the tarball back into /opt/netbox/netbox, including caveats regarding paths potentially being different if restoring from another NetBox installation. --- docs/netbox-enterprise/nbe-backups.md | 63 ++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index 0fc40dc..ace0801 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -69,6 +69,30 @@ Backing up NetBox Enterprise's data manually is reasonably simple, and Kubernete See the [advanced tools documentation](./nbe-troubleshooting.md#accessing-your-cluster-from-the-command-line) for details on connecting to your NetBox Enterprise cluster. +#### Media, Scripts, and Reports + +Media, scripts, and reports are stored in a volume accessible from the NetBox containers. +To back them up, you can run this: + +```shell +export NETBOX_NAMESPACE="kotsadm" && \ +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 && \ + tar -czf - \ + --owner=0 \ + --group=0 \ + media scripts reports' > netbox-data.tar.gz +``` + #### Built-In PostgreSQL The built-in PostgreSQL is deployed using the CrunchyData Postgres Operator. @@ -83,6 +107,7 @@ POSTGRESQL_MAIN_POD="$(kubectl get pod \ -o name \ -n "${NETBOX_NAMESPACE}" \ -l 'postgres-operator.crunchydata.com/role=master' \ + | head -n 1 \ )" && \ kubectl exec "${POSTGRESQL_MAIN_POD}" \ -n "${NETBOX_NAMESPACE}" \ @@ -110,6 +135,7 @@ export REDIS_MAIN_POD="$(kubectl get pod \ -o name \ -n "${NETBOX_NAMESPACE}" \ -l 'app.kubernetes.io/component=master,app.kubernetes.io/name=redis' \ + | head -n 1 \ )" && \ for COMMAND in \ "CONFIG SET auto-aof-rewrite-percentage 0" \ @@ -154,6 +180,7 @@ kubectl exec ${REDIS_MAIN_POD} \ CONFIG SET auto-aof-rewrite-percentage 100' ``` + ### Restoring Your Backups @@ -196,6 +225,33 @@ This will shut down NetBox (and the built-in Redis, if you are using it) but lea When you are done restoring your data, just follow the same steps, unchecking _Enable Restore 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. + +!!! note + 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. + +```shell +export NETBOX_NAMESPACE="kotsadm" && \ +export NETBOX_MAIN_POD="$(kubectl get pod \ + -o name \ + -n "${NETBOX_NAMESPACE}" \ + -l 'app.kubernetes.io/component=netbox' \ + | head -n 1 \ + )" && \ +cat netbox-data.tar.gz | kubectl exec ${NETBOX_MAIN_POD} \ + -n "${NETBOX_NAMESPACE}" \ + -i \ + -c netbox \ + -- tar -xvzf - \ + --no-same-owner \ + --no-same-permission \ + -C /opt/netbox/netbox +``` + #### Built-In PostgreSQL To restore from a dump file, pipe the `netbox.pgsql` created during backup into `psql` in the PostgreSQL pod: @@ -206,6 +262,7 @@ POSTGRESQL_MAIN_POD="$(kubectl get pod \ -o name \ -n "${NETBOX_NAMESPACE}" \ -l 'postgres-operator.crunchydata.com/role=master' \ + | head -n 1 \ )" && \ kubectl exec "${POSTGRESQL_MAIN_POD}" \ -n "${NETBOX_NAMESPACE}" \ @@ -223,7 +280,7 @@ cat netbox.pgsql | kubectl exec "${POSTGRESQL_MAIN_POD}" \ ``` #### Built-In Redis -Since Redis doesn't run in restore mode, there is no need to disable and re-enable append mode. +Since Redis isn't running in restore mode, there is no need to disable and re-enable append mode. All that is necessary is to unpack the files back into place. ```shell @@ -232,6 +289,7 @@ export REDIS_MAIN_POD="$(kubectl get pod \ -o name \ -n "${NETBOX_NAMESPACE}" \ -l 'app.kubernetes.io/component=master,app.kubernetes.io/name=redis' \ + | head -n 1 \ )" && \ cat redis-data.tar.gz | kubectl exec ${REDIS_MAIN_POD} \ -n "${NETBOX_NAMESPACE}" \ @@ -243,6 +301,7 @@ cat redis-data.tar.gz | kubectl exec ${REDIS_MAIN_POD} \ -C /data ``` + \ No newline at end of file From 8530366edb133073108162134088daa995144bf8 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 14:53:04 -0400 Subject: [PATCH 2/7] output part is unnecessary and wrong --- docs/netbox-enterprise/nbe-backups.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index ace0801..e8628fa 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -151,7 +151,7 @@ for COMMAND in \ done ``` -Make sure that those commands output `OK` followed by `aof_rewrite_in_progress:0`, then you're ready to proceed. +Make sure that those commands output `aof_rewrite_in_progress:0`, then you're ready to proceed. Otherwise, just run them again until it says 0. Next, all that's necessary to back up the data in your Redis install is a basic tar command to create an archive from the `/data` directory in the same shell: From 488ce9166fb0ff92e8d0d37a3118088585502491 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 15:15:19 -0400 Subject: [PATCH 3/7] create files in a way they don't mess with directory perms --- docs/netbox-enterprise/nbe-backups.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index e8628fa..7fc8ce9 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -87,10 +87,11 @@ kubectl exec "${NETBOX_MAIN_POD}" \ -c netbox \ -- /bin/sh -c ' \ cd /opt/netbox/netbox && \ + find media scripts reports -type f > /tmp/files.txt && \ tar -czf - \ --owner=0 \ --group=0 \ - media scripts reports' > netbox-data.tar.gz + -T /tmp/files.txt' > netbox-data.tar.gz ``` #### Built-In PostgreSQL @@ -162,10 +163,11 @@ kubectl exec ${REDIS_MAIN_POD} \ -c redis \ -- /bin/sh -c ' \ cd /data && \ + find * -type f > /tmp/files.txt && \ tar -czf - \ --owner=0 \ --group=0 \ - *' > redis-data.tar.gz + -T /tmp/files.txt' > redis-data.tar.gz ``` Finally, turn AOF rewrites back on: From 12a4c31442bddfac7fc3c5ec66364cb3bb709575 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 16:47:20 -0400 Subject: [PATCH 4/7] point at restore-mode pod for data restoration --- docs/netbox-enterprise/nbe-backups.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index 7fc8ce9..852dbbf 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -238,20 +238,20 @@ To restore media, scripts, and reports, you just need to unpack them into the co ```shell export NETBOX_NAMESPACE="kotsadm" && \ -export NETBOX_MAIN_POD="$(kubectl get pod \ +export NETBOX_RESTORE_POD="$(kubectl get pod \ -o name \ -n "${NETBOX_NAMESPACE}" \ - -l 'app.kubernetes.io/component=netbox' \ + -l 'app.kubernetes.io/component=restore-mode' \ | head -n 1 \ )" && \ -cat netbox-data.tar.gz | kubectl exec ${NETBOX_MAIN_POD} \ +cat netbox-data.tar.gz | kubectl exec ${NETBOX_RESTORE_POD} \ -n "${NETBOX_NAMESPACE}" \ -i \ -c netbox \ -- tar -xvzf - \ --no-same-owner \ --no-same-permission \ - -C /opt/netbox/netbox + -C /data ``` #### Built-In PostgreSQL From 9fe73fa40e2a879f4c4dffc441e035d39d837862 Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 17:05:44 -0400 Subject: [PATCH 5/7] fix bad container name --- docs/netbox-enterprise/nbe-backups.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index 852dbbf..6c8e5e1 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -84,7 +84,6 @@ NETBOX_MAIN_POD="$(kubectl get pod \ )" && \ kubectl exec "${NETBOX_MAIN_POD}" \ -n "${NETBOX_NAMESPACE}" \ - -c netbox \ -- /bin/sh -c ' \ cd /opt/netbox/netbox && \ find media scripts reports -type f > /tmp/files.txt && \ From 01b6454535d4544de0bc99c9cd569fae52672aba Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 17:06:46 -0400 Subject: [PATCH 6/7] wrong one --- docs/netbox-enterprise/nbe-backups.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index 6c8e5e1..b3ee178 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -84,6 +84,7 @@ NETBOX_MAIN_POD="$(kubectl get pod \ )" && \ kubectl exec "${NETBOX_MAIN_POD}" \ -n "${NETBOX_NAMESPACE}" \ + -c netbox \ -- /bin/sh -c ' \ cd /opt/netbox/netbox && \ find media scripts reports -type f > /tmp/files.txt && \ @@ -246,7 +247,6 @@ export NETBOX_RESTORE_POD="$(kubectl get pod \ cat netbox-data.tar.gz | kubectl exec ${NETBOX_RESTORE_POD} \ -n "${NETBOX_NAMESPACE}" \ -i \ - -c netbox \ -- tar -xvzf - \ --no-same-owner \ --no-same-permission \ From bbefd797927be78d0ed9ea6215c892e66bbbf6cc Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Thu, 31 Oct 2024 17:50:36 -0400 Subject: [PATCH 7/7] mount into /opt/netbox/netbox instead --- docs/netbox-enterprise/nbe-backups.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/netbox-enterprise/nbe-backups.md b/docs/netbox-enterprise/nbe-backups.md index b3ee178..820a76f 100644 --- a/docs/netbox-enterprise/nbe-backups.md +++ b/docs/netbox-enterprise/nbe-backups.md @@ -250,7 +250,7 @@ cat netbox-data.tar.gz | kubectl exec ${NETBOX_RESTORE_POD} \ -- tar -xvzf - \ --no-same-owner \ --no-same-permission \ - -C /data + -C /opt/netbox/netbox ``` #### Built-In PostgreSQL