Created
July 23, 2026 03:39
-
-
Save Skinner927/df1e6b02212c6a213aa28235af385f9b to your computer and use it in GitHub Desktop.
netbird upgrade script
This file contains hidden or 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
| #!/bin/bash | |
| set -euo pipefail | |
| NB_STOPPED=0 | |
| die() { echo "ERROR: $*"; exit 1; } | |
| title() { printf '%s\n' "$1"; printf '%*s\n' "${#1}" '' | tr ' ' '='; } | |
| iso() { date -u '+%Y-%m-%dT%H_%M_%SZ'; } | |
| traperr() { echo "ERROR: ${BASH_SOURCE[1]} on line ${BASH_LINENO[0]}"; } | |
| set -o errtrace | |
| trap traperr ERR | |
| trapexit() { | |
| local code=$? | |
| if [[ "$NB_STOPPED" -eq 1 ]]; then | |
| title 'Trying to re-start netbird before exiting' | |
| docker compose up -d || echo ' FAILED TO RESTART NETBIRD!' | |
| fi | |
| exit "$code" | |
| } | |
| trap trapexit EXIT | |
| # Begin | |
| cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" || die 'failed to cd to script dir' | |
| title 'Creating backup dir' | |
| mkdir -p backup | |
| BAK="backup/$(iso)" | |
| mkdir "$BAK" || die "Failed to make backup dir $BAK" | |
| title "Making backup in $BAK" | |
| cp -a config.yaml dashboard.env docker-compose.yml proxy.env traefik-dynamic.yaml "${BAK}/" | |
| title "Stopping netbird" | |
| NBS_BAK="${BAK}/netbird-server_var-lib-netbird" | |
| mkdir "$NBS_BAK" || die "Failed mkdir $NBS_BAK" | |
| docker compose stop netbird-server | |
| NB_STOPPED=1 | |
| docker compose cp -a netbird-server:/var/lib/netbird "${NBS_BAK}/" | |
| title "Pulling new images and starting stack back up" | |
| docker compose up -d --pull always --force-recreate --wait --wait-timeout 5 | |
| NB_STOPPED=0 | |
| LOOPS=10 | |
| title "Waiting $LOOPS seconds to ensure containers don't crash" | |
| for loop in $(seq 1 $LOOPS); do | |
| echo "[${loop}/${LOOPS}] Ensuring containers are up" | |
| while IFS= read -r line; do | |
| if ! echo "$line" | grep -q '^running'; then | |
| echo "ERROR: container $(echo "$line" | cut -d' ' -f2) is not running" | |
| echo " $line" | |
| exit 1 | |
| fi | |
| done < <(docker compose ps -a --format '{{.State}} {{.Service}}') | |
| [[ "$loop" -eq "$LOOPS" ]] || sleep 1 | |
| done | |
| echo '' | |
| echo '*********************' | |
| echo ' SUCCESS ' | |
| echo '*********************' | |
| echo "You may delete the backup: rm -rf '$BAK'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment