How to Get Automatic Backup with Mikrotik Configuration via FTP
We may want to back up the configuration of our Mikrotik
device to the FTP
server at regular intervals, we would like to show you a short and beautiful script that we can use for this.
You can run this script system schedule according to a time that we will determine and save your configuration backup on your FTP
server according to the following parameters. By doing this periodically, we will ensure that we receive regular backup.
Backup the saveUserDB Usermanager Database (true / false )
saveSysBackup System Backup (true / false)
EncryptSysBackup System Backup Get encrypted (true / false)
Export saveRawExport System Backup (true / false)
true = yes
False = No
FTPServer Ftp Server Name
FTPPort Ftp Server Port
FTPUser FTP Username
FTPPass FTP Password
As shown in the screenshot below, we open the system scheduler and paste the code below.
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 | : local saveUserDB false : local saveSysBackup true : local encryptSysBackup false : local saveRawExport true : local FTPServer "FtpServerIPorDomain" : local FTPPort 21 : local FTPUser "FtpUsername" : local FTPPass "Password" : local ts [/ system clock get time] : set ts ([: pick $ ts 0 2]. [: pick $ ts 3 5]. [: pick $ ts 6 8]) : local ds [/ system clock get date] : set ds ([: pick $ ds 7 11]. [: pick $ ds 0 3]. [: pick $ ds 4 6]) : local fname ("BACKUP -". [/ system identity get name]. "-". $ ds. "-". $ ts) : local sfname ("/".$fname) : if ($ saveUserDB) do = ( / tool user-manager database save name = ($ sfname. ". umb") : log info message = "User Manager Database Backup Complete" } : if ($ saveSysBackup) do = ( : if ($ encryptSysBackup = true) do = {/ system backup save name = ($ sfname. ". backup")} : if ($ encryptSysBackup = false) do = {/ system backup save dont-encrypt = yes name = ($ sfname. ". backup")} : log info message = "System Backup Complete" } if ($ saveRawExport) do = ( / export file = ($ sfname. ". rsc") : log info message = "Configuration Export File has been created." } : local backupFileName "" : foreach backupFile in = [/ file find] do = { : set backupFileName ("/".diniz/file get $ backupFile name]) : if ([: typeof [: find $ backupFileName $ sfname]]! = "nil") do = { / tool fetch address = $ FTPServer port = $ FTPPort src-path = $ backupFileName user = $ FTPUser mode = ftp password = $ FTPPass dst-path = $ backupFileName upload = yes } } : delay 5s : foreach backupFile in = [/ file find] do = { : if ([: typeof [: find [/ file get $ backupFile name] "BACKUP -"]]! = "nil") do = { / file remove $ backupFile } } : log info message = "Temporary Files Deleted" : log info message = "Auto Backup Complete." |
I hope it has been a useful article.