forked from massimo-filippi/mikrotik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup-config.rsc
61 lines (42 loc) · 2.05 KB
/
backup-config.rsc
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
##
## Automatically backup router's config and upload it to FTP server(s)
## https://github.com/massimo-filippi/mikrotik
##
## script by Maxim Krusina, maxim@mfcc.cz
## created: 2014-03-09
## updated: 2015-12-05
## tested on: RouterOS 6.33.1 / multiple HW devices
##
########## Set variables
## Base filename
:local filename "daily-backup-myroutername"
## FTP server 1 for upload
:local ftp1Address "ftp-1-hostname"
:local ftp1User "ftp-1-username"
:local ftp1Password "ftp-1-password"
:local ftp1Path "ftp-1-path"
## FTP server 2 for upload - if second server is not used, just comment lines bellow
:local ftp2Address "ftp-2-hostname"
:local ftp2User "ftp-2-username"
:local ftp2Password "ftp-2-password"
:local ftp2Path "ftp-2-path"
########## Do the stuff
## Get currrent RouterOS version
:local myVer [/system package update get installed-version];
## Append version number to filename (to not overwrite backups from older RouterOS versions)
:set filename ($filename . "-" . $myVer);
## Backup & Export config to local file
/system backup save name="$filename"
/export file="$filename"
## Upload to .backup to FTP 1
/tool fetch address=$ftp1Address src-path="$filename.backup" user=$ftp1User mode=ftp password=$ftp1Password dst-path=($ftp1Path . $filename . ".backup") upload=yes port=21
## Upload to .rsc to FTP 1
/tool fetch address=$ftp1Address src-path="$filename.rsc" user=$ftp1User mode=ftp password=$ftp1Password dst-path=($ftp1Path . $filename . ".rsc") upload=yes port=21
:if ([:len $ftp2Address] != 0) do={
## Upload to .backup to FTP 2
/tool fetch address=$ftp2Address src-path="$filename.backup" user=$ftp2User mode=ftp password=$ftp2Password dst-path=($ftp2Path . $filename . ".backup") upload=yes port=21
## Upload to .rsc to FTP 2
/tool fetch address=$ftp2Address src-path="$filename.rsc" user=$ftp2User mode=ftp password=$ftp2Password dst-path=($ftp2Path . $filename . ".rsc") upload=yes port=21
}
## Log
:log info ("Configuration backup created on router $[/system identity get name].")