Community discussions

MikroTik App
 
FalconWiFi
just joined
Topic Author
Posts: 13
Joined: Sun Nov 22, 2020 1:49 am

Backup Script RSC

Tue May 04, 2021 9:23 pm

Hi!

I've just made this script, full.rsc, wich does 3 things in the router.
1. Configures email tool so the next script is able to use it.
2. Creates a script that sends a) a full backup to an email address and b) an "rsc" backup to an email address
3. Creates a job in scheduler so the script runs everyday at 23.30.
4. 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):
/tool e-mail
set address=smtp.ionos.es from="" password=blablabla port=587 start-tls=\
    yes user=blablabla

/system script
add dont-require-permissions=no name=BackupEmail owner=blablabla policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    log warning \"Comenzando envio de backups automatico\"\r\
    \n:log info \"Preparando y enviando backup COMPLETO\"\r\
    \n/system backup save name=config\r\
    \n:delay 25s\r\
    \n/tool e-mail send file=config.backup  to=\"blablabla\" from=rb-10.1\
    00.10.1@blablabla body=\"Backup en formato BACKUP adjunto\"\
    \_subject=\"Backup RB 10.100.10.1\"\r\
    \n:delay 10s\r\
    \n:log info \"Preparando y enviando backup RSC\"\r\
    \n/export file=configRSC.rsc\r\
    \n:delay 25s\r\
    \n/tool e-mail send file=configRSC  to=\"blablabla\" from=rb-10.100.1\
    0.1@blablabla body=\"Backup en formato RSC adjunto\" subjec\
    t=\"Backup RSC RB 10.100.10.1\"\r\
    \n:delay 10s\r\
    \n:log warning \"Script de backups automaticos finalizado\""
	
/system scheduler
add interval=1d name=Backups on-event=BackupEmail policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=may/04/2021 start-time=23:30:00


/file remove full.rsc
Sorry for my English.


Have a nice day!
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Backup Script RSC

Tue May 04, 2021 11:20 pm

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"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup Script RSC

Tue May 04, 2021 11:56 pm

+100 for suggest
 
FalconWiFi
just joined
Topic Author
Posts: 13
Joined: Sun Nov 22, 2020 1:49 am

Re: Backup Script RSC

Tue May 04, 2021 11:57 pm

Hi!

As you can read, it's done.
:log warning "Comenzando envio de backups automatico"
:log info "Preparando y enviando backup COMPLETO"
/system backup save name=config
:delay 25s
/tool e-mail send file=config.backup  to="blablabla" from=rb-10.100.10.1@blablabla body="Backup en formato BACKUP adjunto" subject="Backup RB 10.100.10.1"
:delay 10s
:log info "Preparando y enviando backup RSC"
/export file=configRSC.rsc
:delay 25s
/tool e-mail send file=configRSC  to="blablabla" from=rb-10.100.10.1@blablabla body="Backup en formato RSC adjunto" subject="Backup RSC RB 10.100.10.1"
:delay 10s
:log warning "Script de backups automaticos finalizado"
This one is only the script created by step 2 of the full.rsc.
 
FalconWiFi
just joined
Topic Author
Posts: 13
Joined: Sun Nov 22, 2020 1:49 am

Re: Backup Script RSC

Wed May 05, 2021 12:02 am

What I want the script to do, is when the tech imports it, doing "import full.rsc" is the script to ask for a value to put in "Subject".
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup Script RSC

Wed May 05, 2021 12:11 am

Can't be doed.
 
FalconWiFi
just joined
Topic Author
Posts: 13
Joined: Sun Nov 22, 2020 1:49 am

Re: Backup Script RSC

Wed May 05, 2021 1:00 am

Hi!

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.

Thanks for your help.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup Script RSC

Wed May 05, 2021 2:52 pm

Have think to use ether1 mac address / board serial number / sys tem identity instead of ip?
Insteller can set system identity
 
FalconWiFi
just joined
Topic Author
Posts: 13
Joined: Sun Nov 22, 2020 1:49 am

Re: Backup Script RSC

Wed May 05, 2021 7:11 pm

Have think to use ether1 mac address / board serial number / sys tem identity instead of ip?
Insteller can set system identity
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.

Who is online

Users browsing this forum: GoogleOther [Bot], jprietove and 19 guests