Giter Club home page Giter Club logo

netbox_utils's Introduction

backup.py

For use with netbox-docker instances.

This script backs up:

  • the postgres database
  • the media root path
  • the docker working directory; and
  • an API status dump containing version info.

Further reference: Netbox OSS Documentation > Replicating Netbox

Installation

Requires:

Install dependencies:

pip install python-on-whales

Usage

Run, with the name of your docker container instance.

python backup.py netbox-docker-name

Output is a compressed archive (.tar.gz) in the shell working directory.

Example

➜ python backup.py netbox-docker        
backup.py: Start.
Init: Docker name: netbox-docker
Init: Backup datetime: 20240619_091909
Init: Checking for containers of netbox-docker...
Init: Found Docker containers for netbox-docker
Init: ✅ netbox-docker-netbox-1 running
Init: ✅ netbox-docker-postgres-1 running
Init: Docker image: netbox:latest
Init: Docker Netbox version: v3.7.0-2.8.0
Init: Docker working directory: [path to working directory]
Init: Temp directory: ./netbox_backup_20240619_091909/netbox-docker_netbox-latest_v3.7.0-2.8.0
Database backup: Check if postgres container is up...
Database backup: Getting dump...
Database backup: 866.61 KB
Database backup: ✅ Done.
Media directory: Path at /opt/netbox/netbox/media
Media directory: Size: 5179.61 KB
Media directory: Tarring...
tar: Removing leading `/' from member names
Media directory: Copying to local...
Media directory: Clearing temp file in container filesystem
Media directory: ✅ Done.
Docker working directory: Copying...
Docker working directory: ✅ Done.
Dump Netbox status info: Gathering from http://localhost:8080/api/status/ ...
Dump Netbox status info: Received.
Dump Netbox status info: Dumping to file...
Dump Netbox status info: ✅ Done.
Compress backup: Compressing...
Compress backup: Path: backup_netbox-docker_20240619_091909.tar.gz
Compress backup: Filesize: 7127.45 KB
Compress backup: Cleaning up temp folder.
Compress backup: ✅ Done.
backup.py: All done.

Output

./backup_netbox-docker-name_20240619_091034.tar.gz
	> netbox-docker-name_netbox-latest_v3.7.0-2.8.0/
		> netbox-docker-name/
			... [contents of docker working directory]
		> netbox-docker-name-netbox-1/
			media_20240619_091034.tar.gz
		> netbox-docker-name-postgres-1/
			pg_dump.sql
		> netbox-docker-name_status.json

Usage in Debian LXC with minimal Python installed

An environment with minimal Python 3, but no pip and no ability to install system-wide/externally-managed packages.

# Install pip and venv
sudo apt install python3-pip --no-install-recommends --no-install-suggests
sudo apt install python3-venv
# Install this repo
git clone https://github.com/seb26/netbox_utils.git
cd netbox_utils
# Create a venv
python3 -m venv .venv
# Install python-on-whales
.venv/bin/python -m pip install python-on-whales
# Switch to backups directory
mkdir ../backups
cd ../backups
# Run
../netbox_utils/.venv/bin/python ../netbox_utils/backup.py netbox-docker-name

netbox_utils's People

Contributors

seb26 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.