-
Notifications
You must be signed in to change notification settings - Fork 0
/
synchronize.sh
executable file
·62 lines (50 loc) · 1.59 KB
/
synchronize.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
set -e
transfer_section() {
SECTION="$1"
WHERE="$2"
WHERER="$3"
if [ -z "$WHERER" ]
then
WHERER="$WHERE"
fi
echo "$SECTION" >> "$F"
echo "remove [ find $WHERER ]" >> "$F"
if [ ! -z "$WHERE" ]
then
ssh router.foxden.network "$SECTION/export show-sensitive terse where $WHERE" | dos2unix >> "$F"
else
ssh router.foxden.network "$SECTION/export show-sensitive terse" | dos2unix >> "$F"
fi
}
transfer_section_localclause() {
transfer_section "$1" '(!(name~"^local-"))'
}
transfer_section_notdynamic() {
transfer_section "$1" 'dynamic=no'
}
transfer_section_notdynamic_remove() {
transfer_section "$1" '' 'dynamic=no'
}
F="$(mktemp)"
chmod 600 "$F"
echo > "$F"
transfer_section '/ip/dns/static'
transfer_section_notdynamic '/ip/dhcp-server/lease'
transfer_section_notdynamic_remove '/ip/firewall/filter'
transfer_section_notdynamic_remove '/ip/firewall/mangle'
transfer_section_notdynamic_remove '/ip/firewall/nat'
transfer_section_notdynamic_remove '/ipv6/firewall/filter'
transfer_section_notdynamic_remove '/ipv6/firewall/mangle'
transfer_section_localclause '/system/script'
transfer_section_localclause '/system/scheduler'
scp "$F" router-backup.foxden.network:/tmpfs-scratch/transfer.rsc
ssh router-backup.foxden.network "/import file-name=tmpfs-scratch/transfer.rsc"
sleep 1
ssh router-backup.foxden.network "/file remove tmpfs-scratch/transfer.rsc"
rm -f "$F"
ssh router-backup.foxden.network "/system/script/run firewall-update"
cd files
scp -r . "router.foxden.network:/"
scp -r . "router-backup.foxden.network:/"
cd ..