-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_backup.sh
More file actions
executable file
·38 lines (27 loc) · 885 Bytes
/
do_backup.sh
File metadata and controls
executable file
·38 lines (27 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
set -e
source .env
COMPACT=$(/bin/date +%Y%m%d_%H%M)
eval $(ssh-agent -s)
echo "$PRIVATE_KEY" | ssh-add -
trap "ssh-agent -k" EXIT
cd ${CONFDIR}
while read -r line; do
ROUTER="$(echo $line | cut -d':' -f1)"
SSHPORT="$(echo "$line:" | cut -d':' -f2)"
SSHPORT=${SSHPORT:-22}
NEWROUTER="${USERONROUTER}@${ROUTER}"
SSHCREDS="-p ${SSHPORT} ${NEWROUTER}"
SCPCREDS="-P ${SSHPORT}"
echo "Processing $NEWROUTER"
/usr/bin/ssh -n -oStrictHostKeyChecking=no -oConnectTimeout=10 \
${SSHCREDS} "/export file=export_${COMPACT}" &&
/usr/bin/scp ${SCPCREDS} -q ${NEWROUTER}:/export_${COMPACT}.rsc \
${CONFDIR}/${ROUTER} &&
/usr/bin/ssh -n ${SSHCREDS} "/file remove export_${COMPACT}.rsc" &&
sed -i.bak -e "1d" ${CONFDIR}/${ROUTER}
done <"${ROUTERS}"
rm "${CONFDIR}"/*.bak
git add ${CONFDIR}
git commit -m "Autocommit"
echo "SUCCESS"