#! /usr/bin/env sh # backs up configuration for routers # you MUST have ssh access to the routers in question # without a password required. Easiest is to use # ssh certs with on password # also, simplest is to define router in ~/.ssh/config # with port, IP, user, etc.. router=$1 distro=$2 BASEDIR=/home/routers checkDistro () { if [[ "$distro" = "" ]] then ssh $router 'ls /conf' > /dev/null if [ $? ] then echo Detected opnsense router distro=opnsense else ssh $router 'ls /var/ipfire' > /dev/null if [ $? ] then echo Detected ipFire router distro=ipfire fi fi fi } if [[ "$router" != "" ]] then echo Backing up $router mkdir -p $BASEDIR/$router checkDistro case "$distro" in "ipfire") rsync -a --delete $router:/var/ipfire $BASEDIR/$router rsync -a --delete $router:/root $BASEDIR/$router rsync -a --delete $router:/etc $BASEDIR/$router rsync -a --delete $router:/opt $BASEDIR/$router ;; "opnsense") rsync -a --delete $router:/conf $BASEDIR/$router ;; *) echo Invalid router type $distro ;; esac else echo Syntax routers IP_OF_ROUTER fi