Fortigate- Backup Script

Last updated on March 26th, 2018 at 09:24 am

Backup and restore a configuration file using SCP
First of all enable SCP:

config system global
set admin-scp enable
end
Use the same commands to backup a VDOM configuration by first entering the commands:
config global
set admin-scp enable
end
config vdom
edit

Example of bat file:
————————Start forti_BCKP.bat————————-

@echo off





forfiles -p "D:\FORTI-backup" -s -m *.* /D -30 /C "cmd /c del /Q /S @path"

pscp -pw [email protected]@P -l your_user 192.168.140.254:sys_config D:\FORTI-backup\FWBG.conf
"C:\Program Files\WinRAR\WinRAR.exe" a -m3 -s -y -ep1 -r -ta -pYour_rar_Pass "D:\FORTI-BCKP\FORTI-backup.rar" "D:\FORTI-backup\FWBG.conf"
del D:\FORTI-backup\FWBG.conf


wscript "C:\backup\FortiBackup-Email_Notification.vbs"

ren “D:\FORTI-backup\FORTI-BCKP.rar” “FortiBCKP-%date:/=-% %time::=-%.rar”
————————End forti_BCKP.bat————————-

————————Start FortiBackup-Email-Notification.vbs————————-

Set objMail = CreateObject("CDO.Message")
Set objConf = CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Your_Smtp_Server" 'your smtp server domain or IP address goes here
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email
'uncomment next three lines if you need to use SMTP Authorization
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
objFlds.Update
objMail.Configuration = objConf
objMail.From = "[email protected]_domain.com"
objMail.To = "[email protected]"
objMail.Subject = "Forti-Backup"
objMail.TextBody = "Please check attachment"
objMail.AddAttachment "D:\FORTI-backup\FORTI-BCKP.rar"
objMail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objMail = Nothing

————————End FortiBackup-Email-Notification.vbs————————-