Sunday, September 4, 2016

F5 scheduled backup script.

F5 scheduled backup script


I needed an automatic backup solution to backup LTM's and GTM's devices in my environment. The below scripts would generate UCS, scf files and would then transfer the files to FTP server.
 
Create 2 files dailybackup.sh and monthlybackup.sh

Copy the below code into those files. Daily backup will be send to the FTP server and I needed monthly backup which runs once every month to be on the device. The only change that needs to be done here is FTP SERVER IP, FTP USER and FTP PASSWORD and the beginning of the script and it should work fine.
 
Daily – Backup files sent to FTP server
Monthly – Backup files on the F5 devices @ /var/local/usc and /var/local/scf folders


Daily backup script –

#!/bin/bash
#/home/root/dailyf5backup.sh

HOST="<>"      # FTP Server IP
USER="<>"       # FTP User
PASS="<>"    # FTP Password
DIR="/"        # FTP Directory


#Create current date/time stamp variable
DATETIME=$( date '+%Y-%m-%d_%H-%M' )


#Create hostname variable
HOSTNAME=$(uname -n| cut -f 1 -d".")

UCS_FILENAME="${DATETIME}_$HOSTNAME"
SCF_FILENAME="${DATETIME}_$HOSTNAME"


#Delete files that are older than 10 days
find /var/tmp/*.tar -mtime +10 -type f -delete
find /var/tmp/*.scf -mtime +10 -type f -delete
find /var/tmp/*.ucs -mtime +10 -type f -delete
logger -p local0.info -t BIGIP configuration backup started.
cd /config
tmsh save /sys config
tmsh save /sys ucs /var/tmp/$UCS_FILENAME.ucs
tmsh save sys config file /var/tmp/$SCF_FILENAME.scf
logger -p local0.info -t BIGIP configuration upload to $HOST started.
FILE=/var/tmp/$hostname.ucs
TONAME=$hostname-$DATE.ucs
ftp -inv $HOST<    user $USER $PASS
    bin
    lcd /var/tmp
    cd $DIR
    put $UCS_FILENAME.ucs
 put $SCF_FILENAME.scf
 put *.tar
   quit
END_SCRIPT
logger -p local0.info -t BIGIP configuration upload to $HOST completed.
logger -p local0.info -t BIGIP configuration backup completed.
exit 0


Monthly backup script -

#!/bin/bash
#/home/root/monthlyf5backup.sh
#
#UCS Files will be saved to /var/local/ucs/
#SCF Files will be saved to /var/local/scf/

#Create current date/time stamp variable
DATETIME=$( date '+%Y-%m-%d_%H-%M' )

#Create hostname variable
HOSTNAME=$(uname -n| cut -f 1 -d".")


#Uncomment the following line for troubleshooting
#echo $DATETIME

#Create filename variable
UCS_FILENAME="${DATETIME}_$HOSTNAME"


#Uncomment the following line for troubleshooting
#echo $UCS_FILENAME


#Save the system config before saving UCS and SCF files.
tmsh save /sys config


#Create a UCS archive with the filename specified above

#The file extension will be .ucs will be available in the GUI
tmsh save sys ucs "${UCS_FILENAME}"


#Also create an SCF file with the same filename
#The file extension will be .scf won't be available in the GUI
tmsh save sys config file "${UCS_FILENAME}.scf"


#If you don’t delete these files /var will become full fairly quickly
#Change the +31 value (10 days) to whatever suits you
#find /var/local/ucs/*.ucs -mtime +10 -type f -delete
#find /var/local/scf/*.scf -mtime +10 -type f -delete\
#find /var/local/scf/*.scf.tar -mtime +10 -type f -delete
#EOF


To make the above scripts executable run the below command –
Chmod u+x /home/root/backup.sh ( I shored my scripts @ /home/root
..and finally both the scripts to the cronjob daily to run every day, monthly to run on first of every month.


crontab -e
type: crontab -e and add the following line, as the bigip is using vim as editor for crontab, you have just to type i for insert first. After inserting   the line below just hit Escape and type :wq for write and quit

@daily /home/root/dailyf5backup.sh
@monthly /home/root/maonthlyf5.backup.sh


One thing to remember is when the BigIP devices are updated with newer versions of firmware, the copy config does not move these backup scripts so you have to do this all over again or store these scripts in /shared/tmp folder.

Enjoy...!

Wednesday, August 24, 2016

What is F5 license dates and service check date?

On the BigIP device under /config --> you can see a file called bigip.license. This file is typically your license file which has information like what modules are provisioned, list out any additional licenses that were added, platform id. Serial number etc.

Now before upgrading your F5 device its always recommended that admin should reactivate the license. What happens during this process is that the service check date would get updated in bigip.license file which will then allow you to upgrade to the latest and greatest firmware. This is based on your active support contract.

If the license is not Re-Activated and the Service check date is earlier than license check date then the config will not load. You will get an error saying - Config failed to load....

Fail - Service check date is 1/1/2016 and License date is 3/18/2016 (this is just as an example)

Pass - Service check date is 4/1/2016 and License date is 3/18/2016

Service check date - is updated each time when you re-activate the license based on your active support contract.
License check date  - is a static date corresponding to the software version.



The above F5 link provides the license dates for different versions.