mirror of
https://github.com/pothi/mikrotik-scripts.git
synced 2025-06-25 15:38:35 +02:00
Improve backup scripts!
This commit is contained in:
parent
7c39017944
commit
ba16b70013
3 changed files with 69 additions and 31 deletions
|
@ -3,18 +3,36 @@
|
|||
# filename: backup-cron
|
||||
# policy: ftp, read, write, policy, test
|
||||
|
||||
:local adminEmailAddress pothi@duck.com
|
||||
:local deviceIdentity [/system identity get name]
|
||||
:global adminEmail
|
||||
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
|
||||
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
|
||||
|
||||
:log info "Executing the script \"backup-cron\"..."
|
||||
:local backupName "cron"
|
||||
|
||||
/system scheduler export file=cron; :delay 3s
|
||||
:local fileName "$backupName.rsc"
|
||||
:local emailStatus
|
||||
|
||||
/tool e-mail send to="$adminEmailAddress" \
|
||||
subject="[Mikrotik $deviceIdentity] Backup of Cron Entries" \
|
||||
body="See the subject and the attachment." \
|
||||
file=cron.rsc; :delay 10s
|
||||
:log info "\nCreating a $backupName backup..."
|
||||
|
||||
:log info "An email is probably sent to $adminEmailAddress."
|
||||
# remove existing file, if exists for unknown reason
|
||||
/file remove [find name=$fileName]; :delay 1s
|
||||
|
||||
/file remove cron.rsc
|
||||
# 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
|
||||
|
|
|
@ -3,18 +3,38 @@
|
|||
# filename: backup-scripts
|
||||
# policy: ftp, read, write, policy, test
|
||||
|
||||
:local adminEmailAddress "admin@example.com"
|
||||
:local deviceIdentity [/system identity get name]
|
||||
:global adminEmail
|
||||
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
|
||||
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
|
||||
|
||||
:log info "Executing the script \"backup-scripts\"..."
|
||||
:local backupName "scripts"
|
||||
:local fileName "$backupName.rsc"
|
||||
|
||||
/system script export file=scripts; :delay 3s
|
||||
:local emailStatus
|
||||
|
||||
/tool e-mail send to="$adminEmailAddress" \
|
||||
subject="[Mikrotik $deviceIdentity] Backup of Scripts" \
|
||||
body="See the subject and the attachment." \
|
||||
file=scripts.rsc; :delay 10s
|
||||
:log info "\nCreating a $backupName backup..."
|
||||
|
||||
:log info "An email is probably sent to $adminEmailAddress."
|
||||
# remove existing file, if exists for unknown reason
|
||||
/file remove [find name=$fileName]; :delay 3s
|
||||
|
||||
/file remove scripts.rsc
|
||||
# take a backup
|
||||
/system script
|
||||
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."
|
||||
}
|
||||
|
||||
# Optional
|
||||
:delay 5s; /file remove $fileName
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# Cloud Backup
|
||||
|
||||
# requirement/s:
|
||||
:global cloudBackupPass
|
||||
:global cloudPass
|
||||
:if ([:typeof $cloudPass] = "nothing" || $cloudPass = "") do={
|
||||
:log error "cloudPass is not defined or nil."; :error "Error: Check the log"; }
|
||||
|
||||
# permissions required: ftp, read, write, policy, test
|
||||
|
||||
:local backupName "Cloud Backup"
|
||||
|
||||
:log info "\nRunning the script \"cloud-backup\"..."
|
||||
:log info "\nCreating a new cloud backup..."
|
||||
|
||||
/system backup cloud
|
||||
|
||||
|
@ -16,15 +16,15 @@
|
|||
|
||||
remove-file number=0
|
||||
:delay 3s
|
||||
:log info "Existing $backupName is removed to create-and-upload a new backup."
|
||||
:log info " Existing cloud backup is removed to create space for a new backup."
|
||||
|
||||
} else={ :log info "No existing $backupName found."; }
|
||||
} else={ :log info " No existing cloud backup found."; }
|
||||
|
||||
:log info "Creating a new $backupName..."
|
||||
:log info " A new cloud backup is being created..."
|
||||
|
||||
upload-file action=create-and-upload password=$cloudBackupPass
|
||||
:delay 10s
|
||||
upload-file action=create-and-upload password=$cloudPass
|
||||
:delay 30s
|
||||
|
||||
:if ( ([:pick [print as-value] 0]->"status") = "ok" ) do={
|
||||
:log info "$backupName is successful."
|
||||
} else={ :log error "$backupName failed!" }
|
||||
:log info "Cloud backup is successful."
|
||||
} else={ :log error "Cloud backup failed!" }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue