Community discussions

MikroTik App
 
ceylan
newbie
Topic Author
Posts: 27
Joined: Sat Feb 10, 2018 3:03 pm
Location: CYPRUS
Contact:

Generate backup and send it by e-mail

Sat Mar 16, 2019 1:05 pm

I want to learn step by step smtp server configuration and than generate backup and send it by e-mail to my e-mail and i want that monthly automatically. i am trying this ex. " https://wiki.mikrotik.com/wiki/Manual:S ... _by_e-mail " . i have gmail address and you can see my Forwarding and POP/IMAP settings in gmail.
You do not have the required permissions to view the files attached to this post.
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1557
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Generate backup and send it by e-mail

Mon Mar 18, 2019 6:38 am

I am doing exactly that. Here are the settings:
First setup your E-Mail server information. I am using a G-Mail account.
/tool e-mail
set address=smtp.gmail.com from="Router #2" password=Redacted port=587 \
    start-tls=yes user=address@gmail.com

Then the script that creates the files and sends them:
# Policies needed:  ftp, read, policy, sensitive, test
# Policies NOT needed:  password, reboot, write, sniff, romon
:log info "Starting daily backup";
/system backup save name=RB750-2_Daily
/system package print file RB750-2_Version.txt
:delay 00:00:01
/tool e-mail send file=RB750-2_Daily.backup to="jim@Redacted.com" body="Router #2 daily backup file attached." \
   subject="RB750r2-2  $[/system clock get date] at $[/system clock get time]  Backup"
/ export file RB750-2_Daily
:delay 00:00:10
/tool e-mail send file=RB750-2_Daily.rsc,RB750-2_Version.txt to="jim@Redacted.com" body="Router #2 daily script and version files attached." \
   subject="RB750r2-2  $[/system clock get date] at $[/system clock get time]  Script"
:log info "Daily backup script completed"

Then set a schedule. In my case, this router sends backups every day at 22:32:00:
/system scheduler
add interval=1d name="Daily backup" on-event="Daily Backup" policy=\
    ftp,read,write,policy,test,password,sniff,sensitive start-date=\
    jul/12/2016 start-time=22:32:00
 
ceylan
newbie
Topic Author
Posts: 27
Joined: Sat Feb 10, 2018 3:03 pm
Location: CYPRUS
Contact:

Re: Generate backup and send it by e-mail

Fri Mar 29, 2019 11:41 am

YES thnks. i have one more question if you can halp :) when internet usage falls below 10 Mbit and if it exceeds 100 Mbit,can we send e-mail?
 
exogadget
just joined
Posts: 2
Joined: Wed Jan 08, 2020 10:07 pm

Re: Generate backup and send it by e-mail

Wed Jan 15, 2020 5:45 pm

Hi,

I did it in another way, I remove the file before to create new one, but not after delay for mailing:
/file remove [find name="email_bak.backup"];
/system backup save name=email_bak;
:delay 5;
/tool e-mail send file="email_bak.backup" to="xxxxx@gmail.com" from=yyyyy@gmail.com body="See attached file" subject="Mikrotik Backup $[/system identity get name] $[/system clock get date] $[/system clock get time]";
But my question is it possible to save backup file only if settings were changed, for example if last record (but record #0) in "/system history" has later date/time than date/time of existed backup file?
IMHO it seems too much for my charisma to have daily greetings from routers lol, I would like to have the backup just after change only.
 
User avatar
macsrwe
Forum Guru
Forum Guru
Posts: 1008
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Re: Generate backup and send it by e-mail

Thu Jan 16, 2020 2:50 am

The change-only determination is probably too difficult to be worth the effort. You can't compare files in RouterOS (string variables have definite maximum lengths) and there is no easy indicator for "date configuration last modified."

One comment I will make is that I would recommend you use export, and mail the results of that, instead of mailing backup files. Backup files are comparatively huge, many email servers will not accept them, and they are only good for the physical board they were made from; whereas rsc files are smaller, can be used to "clone" to a new board if the old one gets hit by lightning, and can be compared with a simple diff application.

We have all our units email fresh rsc exports to an archival account twice per week, we save the first copy as a baseline, and whenever we need to do a comparison, after we approve the current configuration as acceptable, we copy that to the baseline instead.
 
exogadget
just joined
Posts: 2
Joined: Wed Jan 08, 2020 10:07 pm

Re: Generate backup and send it by e-mail

Thu Jan 16, 2020 10:29 am

The change-only determination is probably too difficult to be worth the effort. You can't compare files in RouterOS (string variables have definite maximum lengths) and there is no easy indicator for "date configuration last modified."
Yeap, you're right. /system history is active only during the user's session. On regular basis only /log is used and there we don't have opportunity to track the changes.

One comment I will make is that I would recommend you use export, and mail the results of that, instead of mailing backup files. Backup files are comparatively huge, many email servers will not accept them, and they are only good for the physical board they were made from; whereas rsc files are smaller, can be used to "clone" to a new board if the old one gets hit by lightning, and can be compared with a simple diff application.

We have all our units email fresh rsc exports to an archival account twice per week, we save the first copy as a baseline, and whenever we need to do a comparison, after we approve the current configuration as acceptable, we copy that to the baseline instead.
That's correct, you are right again. import file after first connect, reboot and that's all.

Who is online

Users browsing this forum: No registered users and 25 guests