Community discussions

 
upnort
newbie
Topic Author
Posts: 47
Joined: Wed Aug 15, 2018 2:03 am

Backup scripts

Thu Sep 06, 2018 9:54 pm

I am new to RouterOS scripting.

I want to automate backups. I am looking for information to format the backup file names with the following information:

$IDENTITY-$ROUTER_MODEL-$ROUTEROS_VERSION-$DATE-$TIME.backup-type

Where $DATE uses the format YYMMDD and $TIME uses the format HHMM.

For example:

MyMikrotik-RB1100-6.42.7-20180906-1348.rsc

or

MyMikrotik-RB1100-6.42.7-20180906-1348.backup

If such information is already available in this forum or wiki just provide links.

Thanks much! :)
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 1715
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Backup scripts

Thu Sep 06, 2018 10:44 pm

It seems not to be so hard .... here you are: http://bfy.tw/JlQ6
Real admins use real keyboards.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Backup scripts

Thu Sep 06, 2018 11:48 pm

:do {
:local IDENTITY [/system identity get name];
:local MODEL [/system resource get board-name];
:local OSVERSION [/system resource get version];

:local array {""; "jan"; "feb"; "mar"; "apr"; "may"; "jun"; "jul"; "aug"; "sep"; "oct"; "nov"; "dec"}
:local DATE [/system clock get date];
:local day [:pick $DATE 4 6];
:local month ([:find $array [:pick $DATE 0 3]]);
:if ($month < 10) do={:set $month ("0" . $month);}
:local year [:pick $DATE 7 11];
:set $DATE ($year . $month . $day);

:local TIME [/system clock get time];
:local hours [:pick $TIME 0 2];
:local minutes [:pick $TIME 3 5];
:local seconds [:pick $TIME 6 8];
:set $TIME ($hours . $minutes . $seconds);

:do {/system backup save name=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME);
} on-error={:log error message="Backup operation failed..."}

:do {/export file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME);
} on-error={:log error message="Export operation failed..."}
#
# E-MAIL SCRIPT IF REQUIRED
#
} on-error={:log error message="Export and Backup script failed..."}

E-MAIL SCRIPT
:do {/tool e-mail
 :local adminmail1 someone@emailaddress.com;
 :local gmailid yourgmailaccount@gmail.com;
 :local gmailuser yourgmailaccount@gmail.com;
 :local gmailpwd your password;
 :local gmailport 587;
 :local gmailsmtp [:resolve "smtp.gmail.com"];
 set address=$gmailsmtp port=$gmailport start-tls=yes from=$gmailid user=$gmailuser password=$gmailpwd;
 send to=$adminmail1 subject=("Backup of " . $IDENTITY) file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME . ".rsc") start-tls=yes;
 send to=$adminmail1 subject=("Backup of " . $IDENTITY) file=($IDENTITY . "-" . $MODEL . "-" . $OSVERSION . "-" . $DATE . "-" . $TIME . ".backup") start-tls=yes;
} on-error={:log error "Backup Email script failed"}
Last edited by ADahi on Thu Sep 13, 2018 8:49 pm, edited 5 times in total.
 
upnort
newbie
Topic Author
Posts: 47
Joined: Wed Aug 15, 2018 2:03 am

Re: Backup scripts

Fri Sep 07, 2018 8:57 pm

@ADahi
Thank you much for sharing! :-D I will try to remember to report my results when I test further.

Who is online

Users browsing this forum: No registered users and 1 guest