Netbox Database and Media Directory Backup Script

820 views
Skip to first unread message

ni...@kloud7.com

unread,
Feb 5, 2019, 3:59:08 PM2/5/19
to NetBox
To make it a bit faster when upgrading to new releases of Netbox and to schedule as a routine cron job I created this **VERY** basic script. The script will back the Netbox Postgre DB and a compressed archive of the Django Media Directory. Each time the backup script runs the DB and Media Directory backup's are placed in a subfolder that is created and named with the date and time the backup was taken. I located the script in /opt/netbox, but it can really be placed in any location on your Netbox host.

There are a few variables at the top of the script you can modify if you server configuration differs from mine:

NETBOX_ROOT_PATH=/opt/netbox <-- The root directory of Netbox 
BACKUP_PATH=/opt/netbox/backups <-- The directory where the backup subfolders will be placed
DATE_TIME=$(date "+%m%d%y_%H.%M.%S") <-- Backup Date / Time Formatting Options
DB_USERNAME=netbox <-- The Postgre DB username. Can be located in Netbox configuration file: configuration.py
DB_PASSWORD="Database Password Here" <-- The Postgre DB password. Can be located in Netbox configuration file: configuration.py


I have this scheduled as a cron job that runs weekly and its been working quite well for the past few weeks. I wanted to share it here to see if anyone would like to try to make this a bit more advanced or at least maybe someone will find it useful. Please feel free to update and repost if any enhancements are added or errors are found in my version. 
netbox_backup.sh

da...@ccscorp.biz

unread,
Feb 11, 2019, 10:04:09 AM2/11/19
to NetBox
Just used it and it works like a charm, thanks!
Reply all
Reply to author
Forward
0 new messages