Community discussions

MikroTik App
 
juaco
just joined
Topic Author
Posts: 15
Joined: Tue Nov 09, 2010 12:15 am

Enhanced mail config backup

Sat Feb 26, 2011 4:36 am

  1. save the script and adjust ScriptName to the name you gave it
  2. set script policies
  3. tweak SystemIdentity, BackupName, BackupInterval, MailDestination, MailSubject and MailBody
  4. set MailBackupRunFromScheduler = false if you just want a one-time run
# makes a config backup and sends it by mail
#
# If MailBackupRunFromScheduler isn't defined
# 1) programs a scheduled run
# 2) when the scheduled run ocurs it does a backup and sends it by mail
#
# Si MailBackupRunFromScheduler = false it does a backup and sends it by mail

# policy: read,write,test,policy,sensitive

# GLOBALS ---------------------------------------------------------------------
:global MailBackupRunFromScheduler;

# LOCALS ----------------------------------------------------------------------
:local ScriptName "mail-backup";

:local SystemIdentity [/system identity get name];
:local BackupName "$SystemIdentity";
:local BackupInterval [:totime "1d"];

:local MailDestination "my@mail.destinacion";
:local MailSubject "Backup $SystemIdentity $[/system clock get date] $[/system clock get time]";
:local MailBody "Backup attached";

# START ---------------------------------------------------------------------
:if ( $MailBackupRunFromScheduler = "scheduled" ) do={
    :put "DEBUG: $ScriptName: programmed execution";
    :log debug "$ScriptName: programmed execution";

    :set MailBackupRunFromScheduler false;
};

:if ( $MailBackupRunFromScheduler != false ) do={
    :put "DEBUG: $ScriptName: programming execution in $BackupInterval";
    :log debug "$ScriptName: programming execution in $BackupInterval";

    /system scheduler remove [find name=$ScriptName];
    /system scheduler add \
    name=$ScriptName \
    on-event=":global MailBackupRunFromScheduler \"scheduled\"; /system script run $ScriptName;" \
    interval=$BackupInterval \
    start-date=[/system clock get date] \
    start-time=[/system clock get time] \
    policy=[:tostr [/system script get [find name=$ScriptName] policy ]] \
    comment="backup mailer";
} else={
    :put "DEBUG: $ScriptName: generating new backup in $SystemIdentity...";
    :log debug "$ScriptName: generating new backup in $SystemIdentity...";

    /file remove [find name="$BackupName.backup"];
    :delay 5;
    /system backup save name="$BackupName";
    :delay 10;

    :put "DEBUG: $ScriptName: emailing backup to $MailDestination...";
    :log debug "$ScriptName: emailing backup to $MailDestination...";

    /tool e-mail send file="$BackupName.backup" to="$MailDestination" subject="$MailSubject" body="$MailBody";

    :set MailBackupRunFromScheduler true;
};

Who is online

Users browsing this forum: No registered users and 24 guests