Community discussions

MikroTik App
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Backup script stoped working after v7 upgrade

Fri Aug 05, 2022 1:57 pm

Hello
a week ago I have upgraded v6 to v7.4 after that the script stopt working
{
:log info "Starting Backup Script...";
:local sysname [/system identity get name];
:local sysver [/system package get system version];
:log info "Flushing DNS cache...";
/ip dns cache flush;
:delay 2;
:log info "Deleting last Backups...";
:foreach i in=[/file find] do={:if ([:typeof [:find [/file get $i name] "$sysname-backup-"]]!="nil") do={/file remove $i}};
:delay 2;
:local smtpserv [:resolve "smtp.mail.ru"];
:local Eaccount "w********x.ru";
:local pass "t********1";
:local backupfile ("$sysname-backup-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".backup");
:log info "Creating new Full Backup file...";
/system backup save name=$backupfile;
:delay 2;
:log info "Sending Full Backup file via E-mail...";
/tool e-mail send from="<$Eaccount>" to=$Eaccount server=$smtpserv port=587 user=$Eaccount password=$pass start-tls=yes file=$backupfile subject=("$sysname Full Backup (" . [/system clock get date] . ")") body=("$sysname full Backup file see in attachment.\nRouterOS version: $sysver\nTime and Date stamp: " . [/system clock get time] . " " . [/system clock get date]);
:delay 5;
:local exportfile ("$sysname-backup-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".rsc");
:log info "Creating new Setup Script file...";
/export verbose file=$exportfile;
:delay 2;
:log info "Sending Setup Script file via E-mail...";
/tool e-mail send from="<$Eaccount>" to=$Eaccount server=$smtpserv port=587 user=$Eaccount password=$pass start-tls=yes file=$exportfile subject=("$sysname Setup Script Backup (" . [/system clock get date] . ")") body=("$sysname Setup Script file see in attachment.\nRouterOS version: $sysver\nTime and Date stamp: " . [/system clock get time] . " " . [/system clock get date]);
:delay 5;
:log info "All System Backups emailed successfully.\nBackuping completed.";
}
what is the problem and how to fix it?
Last edited by DeDMorozzzz on Sat Aug 06, 2022 9:23 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup script stoped working after v7 upgrade

Fri Aug 05, 2022 2:03 pm

What error do YOU ​​get?

I see three errors, and I stopped debugging already at the third line (I don't consider { ):

First: If your data in the script is true, your mail account is compromised.

Second: You haven't tried to look for the error at all, instead you have thrown this script here as it happens.

Third: Right from the third line, the method for determining the version of RouterOS is wrong.
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Re: Backup script stoped working after v7 upgrade

Sat Aug 06, 2022 9:21 am

Hello
thank you for the answer.
This script was found in the net and is used as it is
Thank you for pointing at the email problem.
I know nothing about scripting and how to fix it
The problem is that sistem doesn't even makes a backup files
 
holvoetn
Forum Guru
Forum Guru
Posts: 5326
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Backup script stoped working after v7 upgrade

Sat Aug 06, 2022 10:14 am


I know nothing about scripting and how to fix it
The problem is that sistem doesn't even makes a backup files
That's because the script stops at the very first error. It doesn't even get to the point where it has to make that backup.
You could run the script from terminal and then provide the info about the error ? It will give you an indication on which line/character an error was found, so you can look for it in the script around the same place.
/system script run <script name>


This is an example of a (VERY RAW) script I use for quick and dirty sending of backup.
(I'm sure rex will have plenty of comments on it, but it works ! :lol: )
:log info "backup starts now"
:global backupfile [/system identity get name]
/system backup save name=$backupfile
:delay 10s
/export file=$backupfile
:delay 10s
:log info "backup is made"
/tool e-mail send to="<my mail>" subject=("Mikrotik Backup of " . [/system identity get name]) file=($backupfile . ".backup")
:log info "backup is sent"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup script stoped working after v7 upgrade

Sat Aug 06, 2022 10:15 am

@DeDMorozzzz wrote
This script was found in the net and is used as it is
As I imagined, the usual copy-and-paste without knowing what you're doing.

Couldn't have asked for help where did you find it?

I am not going to correct it, the forum is full of scripts made to backup, some are mine as well.

I certainly have no intention of correcting things found elsewhere.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Backup script stoped working after v7 upgrade

Sat Aug 06, 2022 10:20 am

@holvoetn wrote
(I'm sure rex will have plenty of comments on it, but it works ! :lol: )
just one ;)
[...] subject="Mikrotik Backup of $backupfile" file="$backupfile.backup" [...]

*******************

@DeDMorozzzz
Various soluctions already exist, just search.

For example:
Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), licence, user-manager, dude, other files]
viewtopic.php?f=1&t=175360&p=858564#p858564
 
holvoetn
Forum Guru
Forum Guru
Posts: 5326
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Backup script stoped working after v7 upgrade

Sat Aug 06, 2022 10:37 am

just one ;)
[...] subject="Mikrotik Backup of $backupfile" file="$backupfile.backup" [...]
Somehow I KNEW you were going for that one :lol:
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Re: Backup script stoped working after v7 upgrade

Sun Aug 07, 2022 4:22 am

so you can look for it in the script around the same place.
/system script run <script name>
Ive got this resoult
[admin@Main] /system/script> run backup_to_email
expected end of command (line 23 column 40)
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Re: Backup script stoped working after v7 upgrade

Sun Aug 07, 2022 4:26 am

This is an example of a (VERY RAW) script I use for quick and dirty sending of backup.
(I'm sure rex will have plenty of comments on it, but it works ! :lol: )
Thank you you have solved my problem.
Last edited by DeDMorozzzz on Sun Aug 07, 2022 5:27 am, edited 5 times in total.
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Re: Backup script stoped working after v7 upgrade

Sun Aug 07, 2022 4:28 am


Various soluctions already exist, just search.

For example:
Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), licence, user-manager, dude, other files]
viewtopic.php?f=1&t=175360&p=858564#p858564
thank u I'll try to run it
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 2855
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: Backup script stoped working after v7 upgrade

Sun Aug 07, 2022 10:35 am

The very first check what could be wrong is to check if syntax is correct. How? Look at the screenshot. It's enough to "print" the script and it is showed where the problem is. I have RoS 7.5beta on that device but it works also for 6.x line of ROS.
a3.PNG
You do not have the required permissions to view the files attached to this post.
 
DeDMorozzzz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Tue Aug 22, 2017 7:09 am

Re: Backup script stoped working after v7 upgrade

Sun Aug 07, 2022 1:31 pm

The very first check what could be wrong is to check if syntax is correct. How? Look at the screenshot. It's enogh to "print" the script and it is showed where the problem is. I have RoS 7.5beta on that device but it works also for 6.x line of ROS.
a3.PNG
Thank you very much. It seems to be a good way to find problems

Who is online

Users browsing this forum: Ahrefs [Bot], aoravent, mtest001, phascogale, Soleous75 and 77 guests