-
Notifications
You must be signed in to change notification settings - Fork 55
/
backup-config.rsc
99 lines (69 loc) · 3.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
##
## Automatically backup router's config and upload it to FTP server(s)
## https://github.com/massimo-filippi/mikrotik
##
## script by Maxim Krusina, [email protected]
## created: 2014-03-09
## updated: 2019-01-26
## tested on: RouterOS 6.43.8 / 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"
## Log to Slack
:local notifyViaSlack true
:global SlackChannel "#log"
########## Message to Slack
:if ($notifyViaSlack) do={
:global SlackMessage "Creating configuration backup on router *$[/system identity get name]*";
:global SlackMessageAttachements "";
/system script run "Message To Slack";
}
########## 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
########## Message to Slack
:if ($notifyViaSlack) do={
:global SlackMessage "Backup upload to FTP *$ftp1Address*";
:global SlackMessageAttachements "";
/system script run "Message To Slack";
}
########## Upload to secondary FTP
: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
:if ($notifyViaSlack) do={
:global SlackMessage "Backup upload to FTP *$ftp2Address*";
:global SlackMessageAttachements "";
/system script run "Message To Slack";
}
}
## Log
:log info ("Configuration backup created on router $[/system identity get name].")
########## Message to Slack
:if ($notifyViaSlack) do={
:global SlackMessage "Configuration backup on router *$[/system identity get name]* done";
:global SlackMessageAttachements "";
/system script run "Message To Slack";
}