Skip to content

Instantly share code, notes, and snippets.

@courtney-rosenthal
Created July 5, 2016 03:33
Show Gist options
  • Save courtney-rosenthal/0b95750111228963b0b4393a8b7ab156 to your computer and use it in GitHub Desktop.
Save courtney-rosenthal/0b95750111228963b0b4393a8b7ab156 to your computer and use it in GitHub Desktop.
Perform a backup of an OpenWRT router.
#!/bin/sh
#
# Perform a backup of an OpenWRT router.
#
USAGE="usage: $0 [-v] [-i sshIdentityFile] host backupDir"
iflag=
xflag=
while getopts "i:v" option ; do
case "$option" in
i)
iflag="-i $OPTARG"
;;
v)
xflag='-x'
;;
*)
echo "$USAGE" >&2
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 2 ] ; then
echo "$USAGE" >&2
exit 1
fi
Host="$1"
Dest_Dir="$2"
if [ ! -d ${Dest_Dir} ] ; then
echo "$0: backup destination \"${Dest_Dir}\" does not exist" >&2
exit 1
fi
Archive_File="${Host}-`date +%F`.tar.gz"
set -e $xflag
ssh $iflag root@${Host} sysupgrade --create-backup /tmp/${Archive_File} >/dev/null
scp -q $iflag root@${Host}:/tmp/${Archive_File} ${Dest_Dir}/${Archive_File}
ssh $iflag root@${Host} rm /tmp/${Archive_File}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment