20 May, 2010

Central Fortigate Backup script

Hi,

I have several sites with fortigate as the firewall and a lot of on the fly changes on them, I wrote a script for automatic backup of the fortigates, it uses the following tools:
- PLINK
- 7zip

You need to prepare a FTP site to backup to, I created the site on the machine that runs the backup and this way I can zip it up after the backup completes.

just run it once a day and it will keep history for each day.
change each [] field with your values.


===========================================================
echo off
set user=[username]

rd D:\Backup\Fortigate\Temp /s /q
md D:\Backup\Fortigate\Temp

:1st
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=2nd
goto start_bk

:2nd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=3rd
goto start_bk

:3rd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=7zip
goto start_bk

:start_bk
echo === Backing up %hostName% at %hostIP% ===
echo execute backup config ftp /fortigate/Temp/%hostname%_%hostIP%.conf [traget ftp ip] [ftp user] [ftp password] > Command.txt
plink -ssh %hostIP% -l %user% -pw %pass% -m D:\Work\Fortigates_Backup\Command.txt
del command.txt /q
echo.
goto %next%

:7zip
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
7z.exe a -r "D:\Backup\Fortigate\FG_%DAY%-%MONTH%-%YEAR%.zip" D:\Backup\Fortigate\Temp\*.*

:end

====================================================================

have fun.

3 comments:

  1. This is awesome! Thanks I will try it out and let you know how it works.

    Ryan

    ReplyDelete
  2. You forgot the actual backup command or "Command.txt" file...
    I suppose typing "show" would be enough, no?

    ReplyDelete