Community discussions

MikroTik App
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Script cloud-backup notification

Mon Jul 04, 2022 7:47 pm

Hello Team!!!

I would like to make a script to execute a cloud backup
The idea is, if the hardware die, I will need to download the backup to another router (Same hardware)
Have seen he following script:
https://git.eworm.de/cgit/routeros-scri ... p-cloud.md
I did not find where to change the "to" email address to receive the backup results
I need this email because I will need the "secret-download-key" to download the backup in the other hardware.

Any idea or suggestion will be appreciated!
Thanks in advance.
Regards,
Damián
 
Zacharias
Forum Guru
Forum Guru
Posts: 3459
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Script cloud-backup notification

Mon Jul 04, 2022 7:51 pm

It is not suggested to use a .backup file to another device...
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Tue Jul 05, 2022 12:08 am

One is RB1100Dx4 and the other is RB1100Dx4 Dude Edition.
I recently did a backup and I could restore this in the another manually, I had no problem
Just thinking to have a current backup if some day the first Mikrotik die

Regards,
Damián
 
Zacharias
Forum Guru
Forum Guru
Posts: 3459
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Script cloud-backup notification

Tue Jul 05, 2022 2:56 pm

I recently did a backup and I could restore this in the another manually, I had no problem
I never said it can't be done..
Read the first paragraph here https://wiki.mikrotik.com/wiki/Manual:System/Backup
System's backup file also contain the device's MAC addresses, which are also restored when the backup file is loaded.

So when you restore a .backup to another device you clone the MAC addresses too...
Anyways, if you prefer restoring a .backup rather than a .rsc its certainly you choice...
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Tue Jul 05, 2022 3:47 pm

Zacharias, thanks for your answer
The last time, I reverted the MACs to the originals, so both will work for me.
I just need a way to keep all the configuration updated outside the hardware without depending on humans
If the best option is to do this cloud-backup, I will need the "secret-download-key" if I need to restore the configuration any time.
Any idea?

Thanks in advance.
Regards,
Damián
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Wed Jul 06, 2022 11:04 pm

Hello people!
Any sugestion to make a backup or export file and upload it somewhere out of the Mikrotik automatically?

Thanks.
Regards,
Damián
 
Zacharias
Forum Guru
Forum Guru
Posts: 3459
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Script cloud-backup notification

Wed Jul 06, 2022 11:07 pm

You can send a .backup file or .rsc through Emails too...
e.g. using a script you can create those backup files and then from the MikroTik send them to an email account of yours automatically...

Example viewtopic.php?t=146575
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Wed Jul 06, 2022 11:16 pm

Thanks Zacharias!
I will try soon and I will update this post.

Regards,
Damián
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Fri Jul 08, 2022 10:34 pm

Hello people!!!

I have now the following issue, if I execute the script from the terminal, it does work fine, I get the email correctly but when I schedulle to run the script automatically, I see in the logs the initial log write but nothing else, and I dont get the email.
Any suggestion?

Thanks in advance.
Regards,
Damián
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script cloud-backup notification

Fri Jul 08, 2022 10:53 pm

Suggestion without seeing the script?
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Sat Jul 09, 2022 12:16 am

Sorry, I though maybe someone had the same problem
I didnt think the issue was with the script because it does run correctly without the schedulled task (running from terminal)

Here the script:
/system script
add dont-require-permissions=no name=BackupToEmail owner=soporte policy=ftp,read,policy,test,sensitive source=":log info \"Iniciando backup semanal\";\r\
    \n/system backup save name=Router_Bck_Weekly\r\
    \n/system package print file Router_Version.txt\r\
    \n:delay 00:00:01\r\
    \n/ export file Router_Export_Weekly\r\
    \n:delay 00:00:10\r\
    \n/tool e-mail send file=Router_Bck_Weekly,Router_Export_Weekly.rsc,Router_Version.txt to=\"example@gmail.com\" body=\"Se adjuntan backup y export actua\
    l al \$[/system clock get date].\" \\\r\
    \n   subject=\"Router - Backup y export \$[/system clock get date] a las \$[/system clock get time]\"\r\
    \n:log info \"Backup semanal completado\""

This is the Schedulle:
/system scheduler
add interval=1w name=Bck_Export_Weekly on-event=BackupToEmail policy=ftp,read,write,policy,test,password,sniff,sensitive start-date=jul/08/2022 start-time=18:06:00
Thanks in advance.
Regards,
Damián
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script cloud-backup notification

Sat Jul 09, 2022 1:00 am

For example, without reading all:
Without password permission, how the script can make backup? (backup containing also passwords)
Without write permission, how can save the file? (sended later on email)

"Router_Bck_Weekly" do not exist, is created "Router_Bck_Weekly.backup"

wrong syntax:
print file Router_Version.txt
correct syntax:
print file=Router_Version.txt

You can write delay ":delay 00:00:01" directly as ":delay 1s" and so on...
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Sat Jul 09, 2022 1:33 am

Thanks for your answer!
For example, without reading all:
Without password permission, how the script can make backup? (backup containing also passwords)
Without write permission, how can save the file? (sended later on email)
I just added the password permission and write permission to the script, still the same
Also, the script was working from Terminal as I said
"Router_Bck_Weekly" do not exist, is created "Router_Bck_Weekly.backup"
I dont know why but when I added the ".backup" to the file name, I got to my email account another file called "backup.backup", without the ".backup" I get the 3 files correctly
wrong syntax:
print file Router_Version.txt
correct syntax:
print file=Router_Version.txt
Ok, thanks, I changed this, still the same
You can write delay ":delay 00:00:01" directly as ":delay 1s" and so on...
Thanks!

Any idea?
Thanks in advance.
Regards,
Damián
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1490
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Script cloud-backup notification

Sat Jul 09, 2022 2:41 am

I have a script on all my MT routers that does an export, a backup, and the version, and sends it via E-Mail. That scrip is scheduled every night. Obviously you have to have the E-Mail command already set up.
/system script
add dont-require-permissions=no name="Daily Backup" owner=Administrator policy=\
    ftp,read,write,policy,test,password,sensitive source="# Policies needed:  \
    ftp, read, policy, sensitive, test, write\r\
    \n# Policies NOT needed:  password, reboot, sniff, romon\r\
    \n:log info \"Starting daily backup\";\r\
    \n/system backup save name=RB750r2-3_Daily\r\
    \n/export file=RB750r2-3_Daily\r\
    \n/system package print file=RB750r2-3_Version.txt\r\
    \n:delay 00:00:01\r\
    \n/tool e-mail send file=RB750r2-3_Daily.backup to=\"me@my.domain\" body=\
    \"RasPi switch RB750r2-3 Router daily backup file attached.\" \\\r\
    \n   subject=\"RB750r2-3  \$[/system clock get date] at \$[/system clock g\
    et time]  Backup\"\r\
    \n:delay 00:00:10\r\
    \n/tool e-mail send file=RB750r2-3_Daily.rsc,RB750r2-3_Version.txt to=\
    me@my.domain\" body=\"RasPi switch Router RB750r2-3 daily script and versio\
    n files attached.\" \\\r\
    \n   subject=\"RB750r2-3  \$[/system clock get date] at \$[/system clock g\
    et time]  Script\"\r\
    \n:log info \"Daily backup script completed\"\r\
    \n"
I got this from this forum years ago and modified for my purposes.
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Sat Jul 09, 2022 3:40 am

Thanks K6ccc,
I will test this next monday!

Regards,
Damián
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script cloud-backup notification  [SOLVED]

Sat Jul 09, 2022 10:47 am

@k6ccc
Instead of hardcode subject name, you can make a dynamic name, based on serial, identity etc.

See backup script to gmail here:
viewtopic.php?t=183631
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1490
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Script cloud-backup notification

Sat Jul 09, 2022 8:51 pm

@k6ccc
Instead of hardcode subject name, you can make a dynamic name, based on serial, identity etc.

See backup script to gmail here:
viewtopic.php?t=183631
I have no doubt that it could be better. I am EXTREMELY weak on MT scripting, so modified it only enough to make it work for my purposes.
I'll take a look at the article you linked.
 
rbuserdl
Member Candidate
Member Candidate
Topic Author
Posts: 270
Joined: Thu Mar 22, 2018 1:53 pm

Re: Script cloud-backup notification

Mon Jul 11, 2022 3:56 pm

Hello guys!!
I used the Jotne script and worked fine!!
Thanks a lot!

Who is online

Users browsing this forum: BioMax, holvoetn, kevinds and 31 guests