Community discussions

MikroTik App
 
freemannnn
Forum Veteran
Forum Veteran
Topic Author
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

help for cloud backup script.

Fri Aug 27, 2021 1:56 pm

i want to cloud backup one time per day in case i made changes to my router and i want to revert to something older. so i want the script to delete the old file if exists and uploads the new. (mikrotik should have a create-and-replace command for that)
below script works for 1 time in terminal and after no. also if i place it in scripts menu does not work all the time.
maybe an alternate way with "if" if backup exists on cloud delete it and after upload the new one.

:do {/system backup cloud upload-file action=create-and-upload password=123123123} on-error={/system backup cloud remove-file number=0;/system backup cloud upload-file action=create-and-upload password=123123123}
Last edited by freemannnn on Fri Aug 27, 2021 3:10 pm, edited 1 time in total.
 
freemannnn
Forum Veteran
Forum Veteran
Topic Author
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

Re: help for cloud backup script.

Fri Aug 27, 2021 2:14 pm

i think i got it. tested it and it uploads the file regardless it is exist on the cloud or not.
/system backup cloud {
:local varif [find status="ok"] 
:if ([:len $varif] != 0) do={
/system backup cloud print
/system backup cloud remove-file number=0
/system backup cloud upload-file action=create-and-upload password=123123123
} else={
/system backup cloud upload-file action=create-and-upload password=123123123
}
}
 
iegg
just joined
Posts: 18
Joined: Thu May 27, 2021 10:13 pm

Re: help for cloud backup script.

Thu Nov 11, 2021 3:51 pm

Hi,

Here is my script, which is very similar than the above, but maybe for some people slightly more clear since no use of variables and no code duplication.
:if ([:len [/system backup cloud find status="ok"] ]=1) do={
:put "Removing old backup file..."
/system backup cloud print
/system backup cloud remove-file number=0
} 
:put "Creating and uploading backup file..."
/system backup cloud upload-file action=create-and-upload password="haha"
Note: What is very strange: In order for the backup file to be removable, we first have to print the contents backup cloud. Not very logic at all.

Who is online

Users browsing this forum: Bing [Bot], rogerioqueiroz and 19 guests