View Full Version : Log Backup/Archive Script

2008-02-05, 19:24
Having moved my mgmt server from Windows, to SecurePlatform, I had to write some scripts for backing things up. I have a few more scripts to write, but thought I would share this one with everyone. It will take the previous days log files, compress and archive them into a gzip, ftp them to a server, then cleanup old logs and gzips.. The below is pretty self explanatory, but if ya have any questions I might be able to help.

Works on SecurePlatform, but probably would on IPSO and other *nix platforms as well... Make sure to chmod 777 after you are done in vi.

Note, the way I have things setup... In your home ftp dir you need to have created the path hostname/logs, replace hostname of course with whatever yours is...

# !/bin/sh

# Define string variables!
logdate=`/bin/date --date="yesterday" +%Y-%m-%d`
archivedate=`/bin/date --date="yesterday" +%Y_%m_%d`

# Set Check Point profile for library settings!
. $cpdir/tmp/.CPprofile.sh

# Archive yesterday`s log files!
cd ${localbakdir}
/bin/tar zcf ${localbakdir}${archivename}.tgz ${logname}*

# FTP files to backup server!
ftp -in $ftp_server <<EOC
user ${ftp_username} ${ftp_password}
cd ${remotebakdir}
lcd ${localbakdir}
put ${archivename}.tgz

# Remove archive files older than 14 days from local disk!
/usr/bin/find ${localbakdir}/*".tgz" -mtime +14 -exec /bin/rm {} \;

# Remove log files older than 14 days from local disk!
/usr/bin/find ${localbakdir}/*".log" -mtime +14 -exec /bin/rm {} \;
/usr/bin/find ${localbakdir}/*".logaccount_ptr" -mtime +14 -exec /bin/rm {} \;
/usr/bin/find ${localbakdir}/*".loginitial_ptr" -mtime +14 -exec /bin/rm {} \;
/usr/bin/find ${localbakdir}/*".logptr" -mtime +14 -exec /bin/rm {} \;

2009-02-27, 11:29
Thanks for the script! I am about to implement it on my UTM-3070s. What directory did you put it in?


2009-04-22, 03:40
Hi , I have the same need on my windows 2003 R65 fw. I need to get the "yesterdays" Checkpoint log zipped and transfered to an an ftp server . But the orijinal log file must also be keeped only the temporary zipped one should be deleted . And also i need to get the configuration file prepared and ftped to the samee ftp server. I have 2 batches for that which i didnt wrote. When i manually click and run them at day time they seem to work fine. But i gave 2 entries at the scheduled tasks for these batches which is daily at 01.38 and which is at 02.17 at saturdays. when i look at the Scheduled tasks log file for last nearly 10 days i see 2 or 3 days that says finished successfully with an exiting code 0 (something like that). But mostly i see the below error "The attempt to log on to the account associated with the task failed verify that the tasks run-as name password are valid and try again. And also when i look at the ftp server for the files which sometimes transfered there they seem to be very little in size compared to the orijinal ones which remain at the firewall. I know that the script includes zipping (zip file is taken from oracle) so the sizes of the transfered should be smaller but not at this ratio. also the manual runned batch jobs file size is vry large also according to the scheduled "successful ones". Regards

2009-05-13, 07:52
thanks bro
will check it out.....have some queries.....i dont have any idea on scripting....will as such try it...

2010-01-07, 08:01
Hi all,

I still need the log backup script for windows 2003 server. Any help?


2010-01-07, 09:04
Hi all,

I still need the log backup script for windows 2003 server. Any help?


I use simple one

rem @echo off
FOR /F "tokens=1,2,3,4 delims=/, " %%i in ('date/t') do set file=%%i%%j%%k
Set LOG=c:\mybackups\backup-%file%.tgz
C:\WINDOWS\FW1\R65\fw1\bin\upgrade_tools\upgrade_e xport.exe %LOG% <enter.txt

* Where enter.txt is just an empty file in same directory as the BAT file above.

Just run the bat file as scheduled task

2010-01-07, 10:13
Depending on one's needs, you may not want the day of the week. I have always used YYYYMMDD:

FOR /F "tokens=1,2,3,4 delims=/, " &#37;%i in ('date/t') do set file=%%i%%j%%k

produces: Thu0107

FOR /F "tokens=1,2,3,4 delims=/, " %%i in ('date/t') do set file=%%l%%j%%k

produces: 20100107

* Tested on XP SP2 and Windows 2003

2011-03-14, 16:42
Hello and thanks for the script.

Im new to this and my requirement is to create my backups from my Provider-1 with multiple CMA's and pull the previous months logs and move them to the SAN server. Then at the SAN server zip them to compress them and only keep 6 months worth of logs and delete any older ones.

Any thoughts on how to script the previous months logs in SPLAT

Right now i manually set the dates and cut and paste the following:

mv -v /opt/CPmds-R65/customers/XXX-CMA/CPsuite-R65/fw1/log/2011-01 /LOGS/Security/CHECKPOINT/Provider-1/customers/XXX-CMA/

Then on the SAN server i do:

cd /EXPORTS/LOGS/Security/CHECKPOINT/Provider-1/customers/XXX-CMA
bzip2 -v 2011-01

Any suggestions would be greatly appreciated.