Skip to content

Commit 7627e40

Browse files
author
Carl Hjerpe
committed
Upload AutoBackup script
1 parent 40c48ba commit 7627e40

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

AutoBackup/AutoBackup.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AutoBackup
2+
3+
## Function
4+
The function of this script is to backup MikroTik RouterOS config to FTP
5+
6+
## Notes
7+
This script should be tested and verified after every RouterOS update installed.

AutoBackup/AutoBackup.rsc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:local saveUserDB false
2+
:local saveSysBackup true
3+
:local encryptSysBackup false
4+
:local saveRawExport true
5+
:local verboseRawExport false
6+
7+
:local FTPServer "ftphostname"
8+
:local FTPPort 21
9+
:local FTPUser "ftpusername"
10+
:local FTPPass "ftppassword"
11+
12+
13+
:local ts [/system clock get time]
14+
:set ts ([:pick $ts 0 2].[:pick $ts 3 5].[:pick $ts 6 8])
15+
16+
:local ds [/system clock get date]
17+
:set ds ([:pick $ds 7 11].[:pick $ds 0 3].[:pick $ds 4 6])
18+
19+
:local fname ("BACKUP-".[/system identity get name]."-".$ds."-".$ts)
20+
21+
:if ($saveUserDB) do={
22+
/tool user-manager database save name=($fname.".umb")
23+
:log info message="User Manager DB Backup Finished"
24+
}
25+
26+
:if ($saveSysBackup) do={
27+
:if ($encryptSysBackup = true) do={ /system backup save name=($fname.".backup") }
28+
:if ($encryptSysBackup = false) do={ /system backup save dont-encrypt=yes name=($fname.".backup") }
29+
:log info message="System Backup Finished"
30+
}
31+
32+
if ($saveRawExport) do={
33+
:if ($verboseRawExport = true) do={ /export verbose file=($fname.".rsc") }
34+
:if ($verboseRawExport = false) do={ /export file=($fname.".rsc") }
35+
:log info message="Raw configuration script export Finished"
36+
}
37+
38+
:delay 5s
39+
40+
:local backupFileName ""
41+
42+
:foreach backupFile in=[/file find] do={
43+
:set backupFileName ([/file get $backupFile name])
44+
:if ([:typeof [:find $backupFileName $fname]] != "nil") do={
45+
:log info "Uploading $backupFileName to FTP"
46+
/tool fetch address=$FTPServer port=$FTPPort src-path=$backupFileName user=$FTPUser password=$FTPPass dst-path=$backupFileName mode=ftp upload=yes
47+
}
48+
}
49+
50+
:delay 5s
51+
52+
:foreach backupFile in=[/file find] do={
53+
:if ([:typeof [:find [/file get $backupFile name] "BACKUP-"]]!= "nil") do={
54+
/file remove $backupFile
55+
}
56+
}
57+
58+
:log info message="Successfully removed Temporary Backup Files"
59+
:log info message="Automatic Backup Completed Successfully"

0 commit comments

Comments
 (0)