Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all articles
Browse latest Browse all 409

Mikrotik Auto Backup & Email using PTCL SMTP

$
0
0


This guide is divided in two parts

1) Adding Script
2) Adding Email Server
3) Adding Scheduler to run the script on daily basis

1) Adding Script

The below script does the following function.

1) Backup Complete Mikrotik Configuration
2) Backup User Manager Database
3) Export Complete Mikrotik Configuration

After creating 3 files, it will email them using PTCL SMTP server (You can change it in the script if you are using some other isp smtp server) , and then deletes the files after sending Email to save space on RB (as we all know that RB have very limited storage, so if you dont delete the files created on daily basis, it will soon fill up the storage)

Goto System > Scripts
Click on + icon to add script.
Name it backup-script
In the Source box, paste the below script.

:log info "Backup JOB Started . . . "
:global backupfile configbackup
:global umbackup um_backup
:global mikrotikexport  mtexport_backup 
:log info "Deleting old Backup File If available otherwise ignore & process further . . . "
/file remove $backupfile
/file remove $umbackup
/file remove $mikrotikexport</pre>
/system backup save name=$backupfile
/tool user-manager database save name=$umbackup
/export file=$mikrotikexport

:log info "Backup process pausing for 10s so it complete creating backup file"
:delay 20s
:log info "Start Sending Backup File via Email using PTCL SMTP  . . ."

/tool e-mail send to="aacable@hotmail.com" subject=([/system clock get date] . \
" Mikrotik Config Backup") from=mikrotikuser@ptcl.com.pk file=$backupfile server=119.159.253.205

/tool e-mail send to="aacable@hotmail.com" subject=([/system clock get date] . \
" Mikrotik UM Backup") from=mikrotikuser@ptcl.com.pk file=$umbackup server=119.159.253.205
:delay 50s

/tool e-mail send to="aacable@hotmail.com" subject=([/system clock get date] . \
" Mikrotik Export Backup") from=mikrotikuser@ptcl.com.pk file=$mikrotikexport server=119.159.253.205

:delay 40s
:log info "Backup Finished"
:log info "Deleting Backup File. All Done. Allah Hafiz"
/file remove $backupfile
/file remove $umbackup
/file remove $mikrotikexport

Click on OK to save the script.

Following parameters should be changed as per your local requirements.

to=”aacable@hotmail.com”
Replace it with your email address.

server=119.159.253.205
Replace it with your ISP SMTP Server IP.

from=mikrotikuser@ptcl.com.pk
Replace it with your ISP EMAIL Domain. User name can be anyone, but the domain must be matched with the connected ISP.

2) Adding Email Server

Open Terminal & paste the following config (The server ip will work only If you are connected with the PTCL link)

/tool e-mail set address=119.159.253.205 from=mikrotikuser@ptcl.com.pk password=”" port=25 starttls=no user=”"

Testing the Script . .  .

Now Test the script by using following command at terminal. (Also open the log window so you can see the script results or any error)

First we will enable script logging, so we can see its result / errors etc.

/system logging
add action=echo disabled=no prefix=”" topics=scrip

Now execute the script.

/sys script run backup-script

You may see the following screens if every thing is setup correctly. Also open the LOG window.

(Screenshot Posting Pending)

3) Adding Scheduler to run the script on daily basis

Open Terminal & paste the following command

/system scheduler
add comment="Execute Backup Script Daily at 1am" disabled=no interval=1d name=BackupnMail on-event=backup-script policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive start-date=nov/05/2012 start-time=01:00:00

.
Regard’s
Syed Jahanzaib


Filed under: Mikrotik Related

Viewing all articles
Browse latest Browse all 409

Trending Articles