Page 1 of 1

Backup script to USB

Posted: Tue Jan 31, 2017 10:11 am
by rtorto
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)

Re: Backup script to USB

Posted: Sun Oct 23, 2022 8:17 pm
by spippan
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!";
}

Re: Backup script to USB

Posted: Sat Nov 04, 2023 8:48 am
by daywalkerbt
Work on ROS6. ROS7 DateTime does not work.

Re: Backup script to USB

Posted: Thu Nov 09, 2023 4:40 pm
by spippan
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!";
}

Re: Backup script to USB

Posted: Sat Nov 11, 2023 8:40 pm
by drpioneer

Re: Backup script to USB

Posted: Sun Nov 12, 2023 10:59 pm
by spippan
very impressive