Community discussions

MikroTik App
 
User avatar
shadowskippie
Member Candidate
Member Candidate
Topic Author
Posts: 213
Joined: Tue Dec 21, 2010 6:20 pm

renaming backups

Fri Nov 08, 2013 10:42 am

I need i little help here

When the script runs and creates a backup on my router i need it generate the name as the Router ID + the date + the time.

How do i go about this
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: renaming backups

Fri Nov 08, 2013 8:21 pm

like this?

ros code

{
local id [sys identity get name]
local date [sys clock get date ]
local time [sys clock get time]
sys backup save name="$id;$date;$time"
}
 
User avatar
shadowskippie
Member Candidate
Member Candidate
Topic Author
Posts: 213
Joined: Tue Dec 21, 2010 6:20 pm

Re: renaming backups

Sat Nov 09, 2013 10:16 am

Ah thanks. I've been trying to figure out how to bind the variables together
 
User avatar
shadowskippie
Member Candidate
Member Candidate
Topic Author
Posts: 213
Joined: Tue Dec 21, 2010 6:20 pm

Re: renaming backups

Mon Nov 11, 2013 12:45 pm

Is there anyway to get this working. I think the problem is the special characters that come along with the date and time

ros code

:log info "Starting Backup"
:local id [/system identity get name]
:local time [/system clock get time]
:local date [/system clock get date]
:local file "$id$date$time"
/export compact file=$file
:log info "Pausing for 20s"
:delay 20s
:log info "Sending Backup File via Email"
/tool e-mail send file=$file to="email@domain.co.za" subject=([/system identity get name] . \
" Backup") from=email@domain.co.za
:log info "Backup Complete"
:log info "Pausing for 1m"
:delay 1m
file remove $file
:log info "Cleanup complete"
:log info ([/system identity get name] . \ " Backup Completed")
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: renaming backups

Wed May 18, 2022 9:17 am

I do reply to this old post, since it may help other.

Problem is that file name can not contain /
So to get it to work, this character has to be removed or replaced to some like this
{
:local id [/system identity get name]
:local time [/system clock get time]
:local date [/system clock get date]
:local file "$id_$date_$time"
:local name
:for i from=0 to=([:len $file] - 1) do={ 
  :local char [:pick $file $i]
  :if ($char = "/") do={
    :set $char "-"
  }
  :set name ($name . $char)
}
/export compact file=$name
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12558
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: renaming backups

Wed May 18, 2022 10:58 am

If you also want to save the files so that they are easily sortable, add this 3 lines....
(And also you must be sure than the name of the routerboard do not containing special characters, not only like "/")

{
:local id [/system identity get name]
:local time [/system clock get time]
:local date [/system clock get date]

# rex start
:local arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}
:local today [/system clock get date]
:local date "$[:pick $date 7 11]-$($arrMonths->[:pick $date 0 3])-$[:pick $date 4 6]"
# rex end

:local file "$id_$date_$time"
:local name
:for i from=0 to=([:len $file] - 1) do={ 
    :local char [:pick $file $i]
    :if ($char = "/") do={
        :set $char "-"
    }
    :set name "$name$char"
}
/export compact file=$name
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: renaming backups

Wed May 18, 2022 11:28 am

This way is better, more readable :)

I was looking for how to compare two files if possible, and only take new backup and send it if different from previous backup.
checksum if possible or size.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12558
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: renaming backups

Wed May 18, 2022 11:44 am

I make backup and .rsc, but I compare only the .rsc (ignoring first date line) for see if are present some differencies
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: renaming backups

Wed May 18, 2022 11:54 am

Are you doing that on the router it self?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12558
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: renaming backups

Wed May 18, 2022 12:10 pm

Maybe!...

Technically it is possible, :roll:

but I do it on an external server where I upload the files.

Who is online

Users browsing this forum: No registered users and 17 guests