An easy automatic backup script for F5 LTM which works like a charm

Recently I faced some challenges in creating “automatic backup script” for F5 LTM,  because I am not a regular scripting guy. When I called F5 support to help me out, they asked me to call F5 professional services for help, which is F5’s paid service and unfortunately my project had no budget for that. I was initially shocked when I heard from F5 support that they cannot do such scripting, and the only forum where I can get any help is F5 devcentral community , which is informative and community is very supportive. Although I have posted my query there and few people tried to help me , but somehow it didn’t work. I thought of sharing my experience here, so that people can get benefit and save some unnecessary hassle.

This Backup is used to recover the device from complete crash down situation.

These are the three kind of files you can get, with date appended after your device hostname , if you have successful running script.

f5 backup script

Important points to consider when you make your own backup script :-

  1. Do not use windows notepad to edit this script. You will end up messing lot of things. This script is a Shell script so I would suggest to use VI editor to edit anything in the script.
  2. After editing , use WinSCP to upload or download anything to and from the F5 LTM device.
  3. Transfer your script by WinSCP under “/etc/cron.daily” if you want daily backup, else select other folder available within the “/etc” folder starting from word “cron”.
  4. Now login to F5 LTM CLI , and type in “cd /etc/cron.daily” to get into that folder. You can see all available files with “ll” command in that folder.
  5. Issue “sh -x” command to check for any errors, if any error found carefully read the output. If you want to change anything in script , simply type “vi” you will get into VI editor mode. You can find VI editor commands online by googling around. You can insert anything by “i” and quit by “:wq” command.
  6. If script runs well, then you can see all three files inside your FTP server. Now make it run daily by “chmod 777” command.

Below is the backup script, you only need to edit FTP ip address, username and password according to your environment:-

# Automatic Backup Script for F5 LTM V10″”
#Author “Afroz Ahmad”
b config save /var/tmp/BIG-IP_backup.ucs
export a=`date +”%y%m%d”`
export aa=”$HOSTNAME.$a.ucs”
export b=”/var/tmp/$aa”
mv /var/tmp/BIG-IP_backup.ucs $b

tar -cf /var/tmp/certs.tar /config/ssl
export ff=”$HOSTNAME.$a.certs.tar”
export f=”/var/tmp/$ff”
mv /var/tmp/certs.tar $f

export c=”$HOSTNAME.$a.crontab”
export cc=”/var/tmp/$c”
cp /etc/crontab $cc

export MName=
export MDir=/F5/
export Log=/var/tmp/log.bigip

export UserName=admin
export UserPassword=password

export Machine1f2=$aa
export Machine1f3=$c
export Machine1f4=$ff

ftp -nvd ${MName} <<-END 1>&2 > ${Log}
user ${UserName} ${UserPassword}
put ${b} ${MDir}${Machine1f2}
put ${cc} ${MDir}${Machine1f3}
put ${f} ${MDir}${Machine1f4}

rm -f ${b}
rm -f ${cc}
rm -f ${f}

exit $RTN_CODE

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.