Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 📝 backup-restore procedure #367

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
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
17 changes: 8 additions & 9 deletions docs/operations/backup-restore.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@
The recommended method of backing up Nautobot is simply to get a database dump from PostgreSQL:

```no-highlight
export NAMESPACE=nautobot # Be sure to use the correct namespace here
export POSTGRES_SECRET_NAME=nautobot-postgresql # If you have changed the default make sure you change it here
export POSTGRES_PASSWORD=$(kubectl get secret --namespace $NAMESPACE $POSTGRES_SECRET_NAME -o jsonpath="{.data.postgresql-password}" | base64 --decode)
echo $POSTGRES_PASSWORD | kubectl exec -itn $NAMESPACE statefulset.apps/nautobot-postgresql -- pg_dump --username nautobot --clean --if-exists nautobot > backup.sql
export POSTGRES_PASSWORD=$(kubectl get secret --namespace <my namespace> $POSTGRES_SECRET_NAME -o jsonpath="{.data.password}" | base64 --decode)
echo $POSTGRES_PASSWORD | kubectl exec -it --namespace <my namespace> statefulset.apps/nautobot-postgresql -- pg_dump --username nautobot --clean --if-exists nautobot > backup.sql
```

NOTE: The name of the secret is dependent on the helm release name and may be different in your environment.

Make sure to save your `NAUTOBOT_SECRET_KEY` in a safe place as well:

```no-highlight
kubectl get secret nautobot-env -o jsonpath="{.data.NAUTOBOT_SECRET_KEY}" | base64 --decode
kubectl get secret --namespace <my namespace> nautobot-env -o jsonpath="{.data.NAUTOBOT_SECRET_KEY}" | base64 --decode
```

These commands specific to your deployment can be found by inspecting the notes provided after the install:

```no-highlight
helm status nautobot
helm status --namespace <my namespace> nautobot
```

In addition please make sure to note ALL values used to deploy this helm chart:

```no-highlight
helm get values -o yaml nautobot > nautobot.values.yaml
helm get values --namespace <my namespace> -o yaml nautobot > nautobot.values.yaml
```

As with any backup procedure, these steps should be validated in your environment before relying on them in production.
Expand All @@ -40,13 +39,13 @@ This procedure assumes the [Backup Nautobot](#backup-nautobot) procedure was fol
Install Nautobot using the previous helm values:

```no-highlight
helm install nautobot nautobot/nautobot -f nautobot.values.yaml
helm install --namespace <my namespace> nautobot nautobot/nautobot -f nautobot.values.yaml
```

Upload the backup and restore:

```no-highlight
kubectl cp backup.sql nautobot-postgresql-0:/tmp
export POSTGRES_PASSWORD=$(kubectl get secret --namespace nautobot nautobot-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
echo $POSTGRES_PASSWORD | kubectl exec -itn default statefulset.apps/nautobot-postgresql -- psql -U nautobot -f /tmp/backup.sql
export POSTGRES_PASSWORD=$(kubectl get secret --namespace <my namespace> nautobot-postgresql -o jsonpath="{.data.password}" | base64 --decode)
echo $POSTGRES_PASSWORD | kubectl exec -it --namespace <my namespace> statefulset.apps/nautobot-postgresql -- psql -U nautobot -f /tmp/backup.sql
```
Loading