Backup script stoped working after v7 upgrade

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?

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.

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

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


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 ! :laughing: )

: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"

@DeDMorozzzz wrote

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.

@holvoetn wrote

just one :wink:

[...] 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]
http://forum.mikrotik.com/t/router-crashes-are-wiping-the-config/149189/7

Somehow I KNEW you were going for that one :laughing:

Ive got this resoult
[admin@Main] /system/script> run backup_to_email
expected end of command (line 23 column 40)

Thank you you have solved my problem.

thank u I'll try to run it

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

Thank you very much. It seems to be a good way to find problems