#! /usr/bin/env perl # 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.. use strict; use warnings; my $router=shift; my $distro=shift; my $BASEDIR='/home/routers'; sub checkDistro { $distro = shift; unless ( $distro ) { `ssh $router 'ls /conf' > /dev/null`; # print $? . "\n"; die; if ( $? == 0 ) { print "Detected opnsense router\n"; $distro='opnsense'; } else { `ssh $router 'ls /var/ipfire' > /dev/null`; if ( $? == 0 ) { print "Detected ipFire router\n"; $distro='ipfire'; } } } return $distro; } if ( $router ) { print "Backing up $router\n"; `mkdir -p $BASEDIR/$router`; $distro = &checkDistro( $distro ); if ( $distro eq '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`; } elsif ( $distro eq 'opnsense' ) { `rsync -a --delete $router:/conf $BASEDIR/$router`; } else { print "Invalid router type $distro\n"; } } else { print "Syntax $0 IP_OF_ROUTER\n"; }