Last active
March 9, 2025 17:40
mediocre netbox docker backup favorable over the undecided nothing that is in place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -eu | |
. ../netbox-docker/env/postgres.env | |
_date=$(date +%Y%m%d%H%M) | |
backupdir=/backup/netbox | |
umask 177 | |
# iirc this should be done by a sidecar container or something | |
backupfile=${backupdir}/db-${_date} | |
docker compose exec postgres su postgres -c '/usr/local/bin/pg_dump --dbname=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:5432/${netbox} --format c --exclude-table-data extras_cachedvalue --exclude-table-data extras_objectchange' > ${backupfile} | |
# minimal test | |
file ${backupfile} | grep -q "PostgreSQL custom database dump" || exit 1 | |
gzip -f -1 ${backupfile} | |
# Data Backup | |
backupfile=${backupdir}/objects-${_date}.gz | |
docker compose exec netbox tar -cf - --exclude=".git" --exclude="__pycache__" /opt/netbox/netbox/media /opt/netbox/netbox/reports /opt/netbox/netbox/scripts \ | |
| gzip -1 > ${backupfile} | |
# minimal test | |
tar -tzvf ${backupfile} opt/netbox/netbox/media/image-attachments/.gitignore | grep -q opt/netbox/netbox/media/image-attachments/.gitignore || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i would normally remove the
set -e
and trap ERR to drop a message, just didn't need it now. YMMVin any case, the way it is, if this errors out, you have a failed backup, no questions there. thus the validation steps.