Community discussions

 
Nuri
just joined
Topic Author
Posts: 1
Joined: Mon Sep 10, 2018 1:25 pm

need a script for backup and email with details

Tue Sep 11, 2018 4:05 pm

Hello I need a script where I can do a backup and .rsc export. And send this files to my email.
In bestway the backup and .rsc had a timestamp, datestamp, and the name from my hotspot.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 1585
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: need a script for backup and email with details

Tue Sep 11, 2018 4:18 pm

Real admins use real keyboards.
 
upnort
just joined
Posts: 19
Joined: Wed Aug 15, 2018 2:03 am

Re: need a script for backup and email with details

Thu Sep 13, 2018 7:24 am

Does this help?

I'm trying to learn this too.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 203
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: need a script for backup and email with details

Thu Sep 13, 2018 2:20 pm

Does this help?
Updated check it again
 
User avatar
ognjen
just joined
Posts: 18
Joined: Wed Nov 15, 2017 10:31 am
Location: Serbia

Re: need a script for backup and email with details

Sat Sep 15, 2018 10:40 am

Google is your best friend, so ask him :!:
If u want to send mail from mikrotik, you need first configure email in /tool e-mail

Here is my script for send backup over email:
:log info "Backup to e-mail is started"

:global backupfile ([/system identity get name] . "-" . [/system clock get time])

/system backup save name=$backupfile

:log info "backup pausing for 12s"

:delay 12s

:log info "backup being emailed"

/tool e-mail send to="mikrotik@mydomain.com" subject=([/system identity get name] . "-" . [/system clock get time] . \

" Backup - 172.17.210.2") from=mikrotik@mydomain.com file=$backupfile server=mail.mydomain.com

/tool e-mail send to="it@mydomain.com" subject=([/system identity get name] . "-" . [/system clock get time] . \

" Backup - 172.17.210.2") from=mikrotik@mydomain.com file=$backupfile server=mail.mydomain.com

:delay 10s

:log info "Deleting file from MT"

/file remove "$backupfile"

:log info "Finished Backup Script"
Important!
If you want to use gmail, you need to give access mikrotik to send mail. You can change this configuration in google settings
Be careful with MikroTik Firewall because you can cut the line [yourself - MikroTik] :shock:
 
tigro11
newbie
Posts: 46
Joined: Tue Feb 20, 2018 12:31 am

Re: need a script for backup and email with details

Sun Sep 16, 2018 11:28 pm

if someone needs to make a backup of the system and files of usermanager via ftp, I use this.
I hope to please
######################################strart script#############################################################
# automated backup External ftp
# ftp configuration
:local ftphost "1.1.1.1"
:local ftpuser "backup"
:local ftppassword "**********"
:local ftppath "prova"

# months array
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");

# get time
:local ts [/system clock get time]
:set ts ([:pick $ts 0 2].":".[:pick $ts 3 5]);

# get Date
:local ds [/system clock get date]
# convert name of month to number
:local month [ :pick $ds 0 3 ];
:local mm ([ :find $months $month -1 ] + 1);
:if ($mm < 10) do={ :set mm ("0" . $mm); }
# set $ds to format DD-MM-YYYY
:set ds ([:pick $ds 4 6] ."-". $mm ."-". [:pick $ds 7 11]);

# file name for user manager backup - file name will be UMDB-servername-date-time.umb
:local fname ("/BK-".[/system identity get name]."-".$ds."-".$ts.".umb")
# file name for system backup - file name will be UMDB-servername-date-time.backup
:local fname1 ("/BK-".[/system identity get name]."-".$ds."-".$ts.".backup")
# file name for config export - file name will be UMDB-servername-date-time.rsc
:local fname2 ("/BK-".[/system identity get name]."-".$ds."-".$ts.".rsc")
# file name for user manager backup - file name will be UMDB-servername-date-time.umb
:local fname3 ("/BK-LOG-".[/system identity get name]."-".$ds."-".$ts.".umb")

# backup the data
/tool user-manager database save name=$fname
:log info message="User manager backup finished (1/4).";
/system backup save name=$fname1
:log info message="System backup finished (2/4).";
/export compact file=$fname2
:log info message="Config export finished (3/4).";
/tool user-manager database save-log name=$fname3
:log info message="User manager log backup finished (4/4)."

# upload the user manager backup
:log info message="Uploading user manager backup (1/4)."
/tool fetch address="$ftphost" src-path=$fname user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname" upload=yes
# upload the system backup
:log info message="Uploading system backup (2/4)."
/tool fetch address="$ftphost" src-path=$fname1 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname1" upload=yes
# upload the config export
:log info message="Uploading config export (3/4)."
/tool fetch address="$ftphost" src-path=$fname2 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname2" upload=yes
# upload the user manager log backup
:log info message="Uploading user manager log backup (4/4)."
/tool fetch address="$ftphost" src-path=$fname3 user="$ftpuser" mode=ftp password="$ftppassword" dst-path="$ftppath/$fname3" upload=yes

# delay time to finish the upload - increase it if your backup file is big
:delay 60s;
# find file name start with UMDB- then remove
:foreach i in=[/file find] do={ :if ([:typeof [:find [/file get $i name] "BK-"]]!="nil") do={/file remove $i}; }
:log info message="Configuration backup finished.";
#############################################end script##########################################################################

Who is online

Users browsing this forum: No registered users and 5 guests