Today .... Useful script for Automatic backup for System + UserManagerDB ...
Daily... new file name by time and date!!!
Daily... upload to External FTP!!!
Daily... Clean!!! Save the space ... No duplicate in Mikrotik!!!
First the script:
Code: Select all
/system script
add name=FTP-Backup policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive source="# automated System - UM database backup 2 External FTP\r\
\n# Get time\r\
\n:local ts [/system clock get time]\r\
\n:set ts ([:pick \$ts 0 2].[:pick \$ts 3 5].[:pick \$ts 6 8])\r\
\n# Get Date\r\
\n:local ds [/system clock get date]\r\
\n:set ds ([:pick \$ds 7 11].[:pick \$ds 0 3].[:pick \$ds 4 6])\r\
\n# This line to generate the file name for user manager backup - file name will be UMDB- ServerName\? - Date\? - Time\?\r\
\n:local fname (\"/UMDB-\".[/system identity get name].\"-\".\$ds.\"-\".\$ts.\".umb\")\r\
\n# This line to generate the file name for System backup - file name will be UMDB- ServerName\? - Date\? - Time\?\r\
\n:local fname1 (\"/UMDB-\".[/system identity get name].\"-\".\$ds.\"-\".\$ts.\".backup\")\r\
\n# all above is workaround to get unique \$filename=UserManagerDB - \$filename1=System\r\
\n/tool user-manager database save name=\$fname\r\
\n:log info message=UserManagerBackupFinished;\r\
\n/system backup save name=\$fname1\r\
\n:log info message=SystemBackupFinished;\r\
\n# Upload the UserManagerDB Backup to External FTP - change address to your ftp server + user + pass\r\
\n/tool fetch address=www.1.com src-path=\$fname user=user mode=ftp password=pass dst-path=/ upload=yes\r\
\n# Upload the System Backup to External FTP - change address to your ftp server + user + pass\r\
\n/tool fetch address=www.1.com src-path=\$fname1 user=user mode=ftp password=pass dst-path=/ upload=yes\r\
\n# Delay time to finish the upload - increase it if your backup file is big\r\
\n:delay 60s;\r\
\n# Find file name start with UMDB- then remove\r\
\n:foreach i in=[/file find] do={:if ([:typeof [:find [/file get \$i name] \"UMDB-\"]]!=\"nil\") do={/file remove \$i}}\r\
\n:log info message=UserMangerBackup-SystemBackup-TempRemoved;\r\
\n:log info message=UserManger-SystemBackup2CentOS-Finished;"
1 - /tool fetch address=www.1.com src-path=\$fname user=user mode=ftp password=pass dst-path=/ upload=yes
2 - /tool fetch address=www.1.com src-path=\$fname1 user=user mode=ftp password=pass dst-path=/ upload=yes
The last step is to configure the scheduler to execute the above script at a given time interval. The following command makes sure that the script is executed every day:
Code: Select all
/system scheduler
add comment="" disabled=no interval=1d name="System-UM DB- FTP backup" \
on-event=FTP-Backup start-date=jan/01/1970 start-time=00:00:00
Muntathar