summaryrefslogtreecommitdiff
path: root/mikrotik-backup
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2017-03-09 00:07:04 +0100
committerPeter Palfrader <peter@palfrader.org>2017-03-09 00:07:04 +0100
commitb746fca1a47db87b4f76f5d80862edd684556ef5 (patch)
treef730c875e01514cbf22f4b5a827d0b405bdbdcaa /mikrotik-backup
parentbaf0d13576c5e855a6bd61c407fbbb6bbf56a3c5 (diff)
add mikrotik-backup
Diffstat (limited to 'mikrotik-backup')
-rwxr-xr-xmikrotik-backup62
1 files changed, 62 insertions, 0 deletions
diff --git a/mikrotik-backup b/mikrotik-backup
new file mode 100755
index 0000000..37e759d
--- /dev/null
+++ b/mikrotik-backup
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+# Copyright 2017 Peter Palfrader
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+# /system script add name="backups-create" source={/ export compact file=config.export;
+# system backup save name=config.backup dont-encrypt=yes; }
+#
+# /system scheduler add name="backup" on-event="/system script run backups-create" start-date=jan/01/1970 start-time=00:00:00 interval=10h
+# /system script run backups-create
+#
+# /user group add name="backupgroup" policy="ssh,read,ftp,sensitive"
+# /user add name=backup group=backupgroup address=XXX.YYY/ZZZ password=XXXXXXXX
+#
+# /user ssh-keys import user=backup public-key-file=id_rsa.pub
+
+set -e
+set -u
+set -x
+
+umask 077
+
+user=backup
+hosts="router.noreply.org router2.debian.org"
+ts=$(date +"%Y%M%ST%H%M%S")
+
+rc=0
+for h in $hosts; do
+ r=0
+ dir="$h/$ts"
+ mkdir -p "$dir"
+ scp -B -p "${user}@${h}:config.backup" "$dir/" || r=1
+ scp -B -p "${user}@${h}:config.export.rsc" "$dir/" || r=1
+ if [ "$r" -gt 0 ]; then
+ rmdir "$h/$ts" || true
+ rc="$r"
+ else
+ ln -sf "$ts"/config.backup "$h/config.backup"
+ ln -sf "$ts"/config.export.rsc "$h/config.export.rsc"
+ fi
+done
+
+exit "$r"