Skip to content

Instantly share code, notes, and snippets.

@NiceRath
Last active August 1, 2025 09:30
Show Gist options
  • Save NiceRath/810dfaee6ce6fb32f21a09f5fdf433d0 to your computer and use it in GitHub Desktop.
Save NiceRath/810dfaee6ce6fb32f21a09f5fdf433d0 to your computer and use it in GitHub Desktop.
ArubaCX Script to backup config via SSH with non-admin user (from Linux server)
#!/bin/bash
# SWITCH CONFIG:
# user-group readonly
# 10 permit cli command "show running-config"
# 20 permit cli command "show startup-config"
# 30 permit cli command "no page"
# 40 permit cli command "show logging -r"
# user backupuser group readonly password plaintext ...
# user backupuser authorized-key ssh-ed25519 ...
# ssh server vrf default
# ssh server vrf mgmt
# you will have to connect manually one time in the backup-user's context to accept the correct ssh-hostkey or disable checks (not recommended)
set -eEu -o pipefail
PORT=22
USER='backupuser'
SSH_KEY='/home/backupuser/.ssh/switch_ed25519'
PATH_BACKUP='/backup/switch'
PATH_TMP="/tmp/switch_backup_$(date '+%s')"
mkdir -p "$PATH_TMP"
mkdir -p "$PATH_BACKUP"
# you could just duplicate this block or create a loop - whatever..
NAME='switch1'
IP='192.168.1.251'
mkdir -p "${PATH_BACKUP}/${NAME}"
ssh "${USER}@${IP}" -i "$SSH_KEY" -C 'show startup-config' > "${PATH_TMP}/startup-config"
ssh "${USER}@${IP}" -i "$SSH_KEY" -C 'show running-config' > "${PATH_TMP}/running-config"
ssh "${USER}@${IP}" -i "$SSH_KEY" -C 'show logging -r' > "${PATH_TMP}/logging"
tar -czf "${PATH_BACKUP}/${NAME}/$(date +%Y-%m-%d_%H-%M).tar.gz" "${PATH_TMP}/"*
rm -r "$PATH_TMP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment