pothi.mikrotik-scripts/scripts/backup-cron.rsc

39 lines
1,019 B
Text
Raw Permalink Normal View History

2022-02-20 09:29:29 +05:30
# Backup cron (schedules).
# filename: backup-cron
2022-02-20 09:29:29 +05:30
# policy: ftp, read, write, policy, test
2022-11-08 20:58:08 +05:30
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
2022-02-20 09:29:29 +05:30
2022-11-08 20:58:08 +05:30
:local backupName "cron"
2022-02-20 09:29:29 +05:30
2022-11-08 20:58:08 +05:30
:local fileName "$backupName.rsc"
:local emailStatus
2022-02-20 09:29:29 +05:30
2022-11-08 20:58:08 +05:30
:log info "\nCreating a $backupName backup..."
2022-02-20 09:29:29 +05:30
2022-11-08 20:58:08 +05:30
# remove existing file, if exists for unknown reason
/file remove [find name=$fileName]; :delay 1s
2022-02-20 09:29:29 +05:30
2022-11-08 20:58:08 +05:30
# create a backup of cron entries
/system scheduler export file=$fileName
:delay 3s
/tool e-mail
:do { send to="$adminEmail" subject="Backup of $backupName" \
body="See the subject and the attachment." file=$fileName
} on-error={ :log error "Error sending email." }
:do { :delay 5s; :set emailStatus [get last-status] } while=( $emailStatus = "in-progress" )
:if ( $emailStatus = "failed" ) do={
:log error "Backup failed!"
} else={
:log info "Backup is taken and is sent to $adminEmail."
}
/file remove $fileName