Community discussions

MikroTik App
 
rtorto
just joined
Topic Author
Posts: 4
Joined: Thu Jul 02, 2015 4:30 pm

Backup script to USB

Tue Jan 31, 2017 10:11 am

Hi

I have mounted my USB key to file/USB
I cant get my backup script to save to USB/"filename"

The script works just fine when i don't add the USB/ string.

/system backup save name=("FILE-".[/system clock get time])
The backup is saved as FILE-TIMESTAMP.backup

I need it to save the file to USB/FILE-TIMESTAMP.backup

Can anyone help me to add the USB/ in the string ? when i use / my script stop with error:
Failed to save system configuration backup
action failed (6)
 
User avatar
spippan
Member
Member
Posts: 333
Joined: Wed Nov 12, 2014 1:00 pm
Location: Austria

Re: Backup script to USB

Sun Oct 23, 2022 8:17 pm

i wrote my own script to create a binary and a cleartext backup with hostname, rOS version, timestamp, etc.
this script writes a backup to a given path on "disk1" which in my case is a 32GB USB Flash drive formated to ext via routerOS
creates the files if there is enough space on FLASH SYS-DISK (otherwise one could crash the router EVEN if the destination is an EXTERNAL DISK or other disk than internal flash!!)

the default free disk which needs to be available is 1MB (set in ":local freeStoreThresh 1024;")

gives log messages to track for
can be scheduled to run every 24h at least and scales up to desired frequency

mt-forum-usb-backup-note.png
hope it helps
some "documentation" :-D via comments
:log info "primulus_CONFBKB::dailyConfigBackupD START";

#fetch timestamp stuff
:local dSysDateTime [/system clock get date]
:local dDay [ :pick $dSysDateTime 4 6 ]
:local dMon [ :pick $dSysDateTime 0 3 ]
:local dYear [ :pick $dSysDateTime 7 11 ]

#fetch rOS version
:local rosversionFull [/system resource get version]
:local rosversion [:pick [/sys reso get version] 0 [[:find [/sys reso get version] " "]]]

#get free storage ind KB
:local freeStoreK [:tonum [([/sys reso get free-hdd-space]/1024)]]
#set desired free storage threshold in KB
:local freeStoreThresh 1024;

#build destination path and filename to create
:local sBakPath "disk1/backups/configs/automated/";
:local sStamp "$dYear-$dMon-$dDay";
:local sHostname [/system identity get name];
:local sBakFileName "$sBakPath$sHostname_v$rosversion_$sStamp.backup";
:local sBakScrName "$sBakPath$sHostname_v$rosversion_$sStamp.scr";


:log warning "primulus_CONFBKB::Free Disk is --- $freeStoreK KB / routerOS $rosversionFull";

#check if free disk space is available on FLASH SYSTEM DISK
#FLASH SYS-DISK is used to "pre cache"/create the files we move to the BKP PATH as soon as file is created
:if ( $freeStoreK >= $freeStoreThresh ) do={
    :log info "primulus_CONFBKB::SYSTEM Config BACKUP --> $sBakFileName";
    /system backup save name=$sBakFileName;
    /export verbose show-sensitive file=$sBakScrName;
    :log info "primulus_CONFBKB::dailyConfigBackupD DONE";
} else={
    #Backup is NOT created and an error msg is barked to the log! d'uh
    :log error "primulus_CONFBKB::dailyConfigBackupD NOT DONE! Free Storage LOW!";
}
You do not have the required permissions to view the files attached to this post.
 
daywalkerbt
just joined
Posts: 1
Joined: Sat Nov 04, 2023 8:43 am

Re: Backup script to USB

Sat Nov 04, 2023 8:48 am

Work on ROS6. ROS7 DateTime does not work.
Last edited by tangent on Sat Nov 04, 2023 11:25 am, edited 1 time in total.
Reason: removed full-text quote of prior post in a short thread
 
User avatar
spippan
Member
Member
Posts: 333
Joined: Wed Nov 12, 2014 1:00 pm
Location: Austria

Re: Backup script to USB

Thu Nov 09, 2023 4:40 pm

Work on ROS6. ROS7 DateTime does not work.
hi

oh thanks for the reminder - i corrected it yet but forgot to upload here:
:log info "primulus_CONFBKB::dailyConfigBackupD START";

#fetch timestamp stuff
:local dSysDateTime [/system clock get date]
:local dDay [ :pick $dSysDateTime 8 10 ]
:local dMon [ :pick $dSysDateTime 5 7 ]
:local dYear [ :pick $dSysDateTime 0 4 ]

#fetch rOS version
:local rosversionFull [/system resource get version]
:local rosversion [:pick [/sys reso get version] 0 [[:find [/sys reso get version] " "]]]

#get free storage ind KB
:local freeStoreK [:tonum [([/sys reso get free-hdd-space]/1024)]]
#set desired free storage threshold in KB
:local freeStoreThresh 1024;

#build destination path and filename to create
:local sBakPath "sata2/backups/configs/automated/";
:local sStamp "$dYear-$dMon-$dDay";
:local sHostname [/system identity get name];
:local sBakFileName "$sBakPath$sHostname_v$rosversion_$sStamp.backup";
:local sBakScrName "$sBakPath$sHostname_v$rosversion_$sStamp.scr";


:log warning "primulus_CONFBKB::Free Disk is --- $freeStoreK KB / routerOS $rosversionFull";

#check if free disk space is available on FLASH SYSTEM DISK
#FLASH SYS-DISK is used to "pre cache"/create the files we move to the BKP PATH as soon as file is created
:if ( $freeStoreK >= $freeStoreThresh ) do={
    :log info "primulus_CONFBKB::SYSTEM Config BACKUP --> $sBakFileName";
    /system backup save name=$sBakFileName;
    /export verbose show-sensitive file=$sBakScrName;
    :log info "primulus_CONFBKB::dailyConfigBackupD DONE";
} else={
    #Backup is NOT created and an error msg is barked to the LOG! 
    :log error "primulus_CONFBKB::dailyConfigBackupD NOT DONE! Free Storage LOW!";
}
 
drpioneer
just joined
Posts: 10
Joined: Mon Nov 01, 2021 8:33 am

Re: Backup script to USB

Sat Nov 11, 2023 8:40 pm

 
User avatar
spippan
Member
Member
Posts: 333
Joined: Wed Nov 12, 2014 1:00 pm
Location: Austria

Re: Backup script to USB

Sun Nov 12, 2023 10:59 pm

very impressive

Who is online

Users browsing this forum: No registered users and 21 guests