Hey,
Just wanting to know what is recommend the best way to export/backup the data that has been placed into netbox system?
The wiki and docs doesn't really talk about it.
thanks.
Because the data is stored in PostgreSQL, the best thing to do is become familiar with standard PostgreSQL backup and restore procedures. As for exports, that could be implemented as a CSV download link from Netbox.
As @eronlloyd said, a simple PostgreSQL dump will do it. For example:
sudo -u postgres pg_dump netbox > netbox.sql
To restore the data to an empty database:
sudo -u postgres psql netbox < netbox.sql
Hi,
I am trying to migrate netbox but I am failing at the restoring part.
I ran the command "sudo -u postgres psql netbox < netbox.sql" for restoring and I am getting the following error. I think it has to do with some permissions but not sure. I am not much familiar with postgres db, docker etc. but somehow I was able to get netbox running. Can anyone please help?
Thanks.
After I run the command I am getting the following error
sudo -u postgres psql netbox < db_dump_2018-12-03.sql
could not change directory to "/root/netbox-docker"
SET
SET
ERROR: unrecognized configuration parameter "idle_in_transaction_session_timeout"
SET
SET
SET
SET
ERROR: unrecognized configuration parameter "row_security"
S
Just for completeness, you should probably also backup the media and report directories.
In case it's helpful, this is the bash script I'm using to push database exports to Dropbox. It's smart enough to compare the checksum against the last backup and only save & push dumps that are changed from the last one.
I cloned Dropbox-Uploader to /opt/Dropbox-Uploader and followed his installation steps.
If you don't have zip installed, install it with sudo apt install zip
Then I created this file in the home directory of the postgres user (/var/lib/postgresql/backup.sh). Make it executable with chmod +x /var/lib/postgresql/backup.sh.
#!/bin/bash
time=$(date +%Y%m%d-%H-%M-%S)
mkdir /tmp/netbox-backups
pathtobackup=/tmp/netbox-backups/netbox-$time.sql
pathtochecksum=/tmp/netbox-backups/latest.md5
echo "Running Netbox backup at $time"
# backup the database
/usr/bin/pg_dump netbox > $pathtobackup
# generate a checksum of the backup
md5=($(md5sum $pathtobackup))
# compare against last checksum
lastmd5="`cat $pathtochecksum`"
if [ "$md5" = "$lastmd5" ]; then
echo "Backups match, removing this instance"
rm $pathtobackup
else
echo "New checksum, zipping and pushing to Dropbox"
/usr/bin/zip -9 $pathtobackup.zip $pathtobackup
/opt/Dropbox-Uploader/dropbox_uploader.sh upload $pathtobackup.zip .
echo "$md5" > $pathtochecksum
fi
To automate the backup, I switched over to the postgres user (su - postgres) and added this to its crontab (crontab -e). This example runs it every 30 minutes:
00,30 * * * * /var/lib/postgresql/backup.sh >> /tmp/netbox-backup/backup.log 2>&1
Per @mchlumsky, this script doesn't include the media or reports directories, so consider other ways to save those.
Most helpful comment
In case it's helpful, this is the bash script I'm using to push database exports to Dropbox. It's smart enough to compare the checksum against the last backup and only save & push dumps that are changed from the last one.
I cloned Dropbox-Uploader to
/opt/Dropbox-Uploaderand followed his installation steps.If you don't have
zipinstalled, install it withsudo apt install zipThen I created this file in the home directory of the
postgresuser (/var/lib/postgresql/backup.sh). Make it executable withchmod +x /var/lib/postgresql/backup.sh.To automate the backup, I switched over to the postgres user (
su - postgres) and added this to its crontab (crontab -e). This example runs it every 30 minutes:Per @mchlumsky, this script doesn't include the
mediaorreportsdirectories, so consider other ways to save those.