help for cloud backup script.

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}

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
}
}

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.