I’ve just made this script, full.rsc, wich does 3 things in the router.
Configures email tool so the next script is able to use it.
Creates a script that sends a) a full backup to an email address and b) an “rsc” backup to an email address
Creates a job in scheduler so the script runs everyday at 23.30.
Deletes itself.
I’m not a programmer, but it was easy to do it as I did. But I want to make it more friendly.
I want my techs to install this in every router they configure, so I want it to ask to the tech (when he writes “import full.rsc” in terminal) wich subject to use when sending the emails.
Could you help me? Feel free to use this code and edit for whatever you want
Here’s full.rsc source (sensible information is replaced by blablabla, but is used as it should in real rsc):
I do suggest that you also send an export file. If you for some reason need to change to an other type of MT router, it will be hard to restore a backup file.
Here is my Gmail backup script.
#
# Created Jotne 2020 v1.0
#
# Takes two different backup and send then to email
#
# backup.rsc readable backup
# Certificates, the Dude and Usermanager are also NOT exported or backed up fully and should be backed up separately. Can be used to restore config to different routers
#
# backup.bin binary backup
# Binary backup that can only be used to fully restored the same router.
#
:local email "xyz@gmail.com"
/export file=backup
:delay 2s
/system backup save name=bin
:delay 2s
:local date [/system clock get date]
:local time [/system clock get time]
:local info [/system identity get name]
:local serial [/system routerboard get serial-number]
:local files "backup.rsc,bin.backup"
/tool e-mail send to="$email" subject="Mikrotik: Backup $info $serial" file=$files body="Automatic Backup of $info $serial at $date $time."
:delay 20s
/file remove backup.rsc
/file remove backup.bin
:log info message="Backup router=$info serial=$serial ok"
Thanks for your answers. As what I wanted to do cant be done, this is what the final script looks like:
:log warning "Comenzando envio de backups automatico"
:local email "blablabla"
:local fecha [/system clock get date]
:local hora [/system clock get time]
:local nombre [/system identity get name]
:local archivos "config.backup, configRSC.rsc"
#METEMOS LA IP CON NETMASK DE LA VPN EN UNA VARIABLE
:global ipaddress [/ip address get [find interface="VPN-blablabla"] address];
#ELIMINAMOS EL NETMASK
set ipaddress [:put [:pick $ipaddress 0 [:find $ipaddress "/"]]]
# AQUI DEFINIMOS LA IP ACTUAL SIN NETMASK EN currentIP
:local ipvpn $ipaddress
:log info "Preparando archivos de backup. Esto tardara 50 segundos."
/system backup save name=config
:delay 25s
/export file=configRSC.rsc
:delay 25s
:log info "Archivos de backup listos. Enviando..."
/tool e-mail send file=$archivos to=$email from="rb-$ipvpn@blablabla" body="Archivos de Backup generados en $fecha - $hora" subject="Backup $ipvpn"
:delay 10s
:log warning "Script de backups automaticos finalizado"
My techs will be instructed to allways use same name for that interface.
Yes, I've thinked about it, but in the way that we have our systems is more adecuate to use that IP (unique to the router and identified in a database)
But thanks for the suggestion. I'm using this version of the script now and it works perfectly.