on 16-Aug-2011 14:45
Beginning with BIG-IP version 11, the idea of templates has not only changed in amazing and powerful ways, it has been extended to be far more than just templates. The replacement for templates is called iAppTM. But to call the iAppTM just a template would be woefully inaccurate and narrow. It does templates well, and takes the concept further by allowing you to re-enter a templated application and make changes. Previously, deploying an application via a template was sort of like the Ron Popeil rotisserie: “Set it, and forget it!” Once it was executed, the template process was over, it was up to you to track and potentially clean up all those objects. Now, the application service you create based on an iAppTM template effectively “owns” all the objects it created, so any change to the deployment adds/changes/deletes objects as necessary. The other exciting change from the template perspective is the idea of strictness. Once an application service is configured, any object created that is owned by that service cannot be changed outside of the service itself. This means that if you want to add a pool member, it must be done within the application service, not within the pool. You can turn this off, but what a powerful protection of your services!
Update for v11.2 - https://devcentral.f5.com/s/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1090565/Ar...
I received a request from one of our MVPs that he’d really like to be able to allow his users to schedule configuration backups without dropping to the command line. Knowing that the iAppTM feature was releasing soon with version 11, I started to see how I might be able to coax a command line configuration from the GUI. In training, I was told that “anything you can do in tmsh, you can do with an iAppTM.” This is excellent, and the basis for why I think they are going to be incredibly popular for not only controlling and managing applications, but also for extending CLI functions to the GUI. Anyway, so in order to schedule a configuration backup, I need:
That’s really all there is to it.
Thankfully, the background work is already done courtesy of a config backup codeshare entry by community user Colin Stubbs in the Advanced Design & Config Wiki. I did have to update the following bigpipe lines from the script:
bigpipe export oneline “${SCF_FILE}” to tmsh save /sys config one-line file “${SCF_FILE}”
bigpipe export “${SCF_FILE}” to tmsh save /sys config file "${SCF_FILE}"
bigpipe config save “${UCS_FILE}” passphrase “${UCS_PASSPHRASE}” to tmsh save /sys ucs "${UCS_FILE}" passphrase "${UCS_PASSPHRASE}"
bigpipe config save “${UCS_FILE}” to tmsh save /sys ucs "${UCS_FILE}"
Also, I created (according the script comments from the codeshare entry) a /var/local/bin directory to place the script and a /var/local/backups directory for the script to dump the backup files in. These are optional and can be changed as necessary in your deployment, you’ll just need to update the script to reflect your file system preferences. Now that I have everything I need to support a backup, I can move on to the iAppTM template configuration.
A template consists of three parts: implementation, presentation, and help. You can create an empty template, or just start with presentation or help if you like.
I’ll focus on the presentation first, and then the implementation. I’ll forego the help section in this article.
The reason I’m starting with the presentation section of the template is that the implementation section’s Tcl variables reflect the presentation methods naming conventions. I want to accomplish a few things in the template presentation:
The APL code for this looks like this:
section time_select {choice day_select display "large" { "Daily", "Weekly", "Monthly" }optional ( day_select == "Weekly" ) {
choice dow_select display "medium" { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }}optional ( day_select == "Monthly" ) {
message dom_warning "The day of the month should be the 1st-28th. Selecting the 29th-31st will result in missed backups on some months."
choice dom_select display "medium" tcl {
for { set x 1 } { $x < 32 } { incr x } {
append dom "$x\n"
}return $dom
}}choice hr_select display "medium" tcl {
for { set x 0 } { $x < 24 } { incr x} {
append hrs "$x\n"
}return $hrs
}choice min_select display "medium" tcl {
for { set x 0 } { $x < 60 } { incr x } {
append mins "$x\n"
}return $mins
}}text {time_select "Backup Schedule"
time_select.day_select "Choose the frequency the backup should occur:"
time_select.dow_select "Choose the day of the week the backup should occur:"
time_select.dom_warning "WARNING: "
time_select.dom_select "Choose the day of the month the backup should occur:"
time_select.hr_select "Choose the hour the backup should occur:"
time_select.min_select "Choose the minute the backup should occur:"
}
A few things to point out. First, the sections (which can’t be nested) provide a way to set apart functional differences in your form. I only needed one here, but it’s very useful if I were to build on and add options for selecting a UCS or SCF format, or specifying a mail address for the backups to be mailed to. Second, order matters. The objects will be displayed in the template as you define them. Third, the optional command allows me to hide questions that wouldn’t make sense given previous answers. If you dig into some of the canned templates shipping with v11, you’ll also see another use case for the optional command. Fourth, you can use Tcl commands to populate fields for you. This can be generated data like I did above, or you can loop through configuration objects to present in the template as well. Finally, the text section is where you define the language you want to appear with each of your objects. The nomenclature here is section.variable. To give you an idea what this looks like, here is a screenshot of a monthly backup configuration:
Once my template (f5.archiving) is saved, I can configure it in the Application Services section by selecting the template. At this point, I have a functioning presentation, but with no implementation, it’s effectively useless.
Now that the presentation is complete, I can move on to an implementation. I need to do a couple things in the implementation:
Here is the implementation section:
array set dow_map {
Sunday 0
Monday 1
Tuesday 2
Wednesday 3
Thursday 4
Friday 5
Saturday 6
}set hr $::time_select__hr_select
set min $::time_select__min_selectset infile [open "/etc/cron.d/f5backups" "w" "0755"]
puts $infile "SHELL=\/bin\/bash"
puts $infile "PATH=\/sbin:\/bin:\/usr\/sbin:\/usr\/bin"
puts $infile "#MAILTO=user@somewhere"
puts $infile "HOME=\/var\/tmp\/"
if { $::time_select__day_select == "Daily" } {
puts $infile "$min $hr * * * root \/bin\/bash \/var\/local\/bin\/f5backup.sh 1>\/var\/tmp\/f5backup.log 2>\&1"
} elseif { $::time_select__day_select == "Weekly" } {
puts $infile "$min $hr * * $dow_map($::time_select__dow_select) root \/bin\/bash \/var\/local\/bin\/f5backup.sh 1>\/var\/tmp\/f5backup.log 2>\&1"
} elseif { $::time_select__day_select == "Monthly" } {
puts $infile "$min $hr $::time_select__dom_select * * root \/bin\/bash \/var\/local\/bin\/f5backup.sh 1>\/var\/tmp\/f5backup.log 2>\&1"
}close $infile
A few notes:
A succesful configuration of the application service results in this file configuration for /etc/cron.d/f5backups:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
#MAILTO=user@somewhere
HOME=/var/tmp/
54 15 * * * root /bin/bash /var/local/bin/f5backup.sh 1>/var/tmp/f5backup.log 2>&1
So this backup is scheduled to run daily at 15:54. This is confirmed with this directory listing on my BIG-IP:
[root@golgotha:Active] bin # ls -las /var/local/backups
total 2168
8 drwx------ 2 root root 4096 Aug 16 15:54 .
8 drwxr-xr-x 9 root root 4096 Aug 3 14:44 ..
1076 -rw-r--r-- 1 root root 1091639 Aug 15 15:54 f5backup-golgotha.test.local-20110815155401.tar.bz2
1076 -rw-r--r-- 1 root root 1092259 Aug 16 15:54 f5backup-golgotha.test.local-20110816155401.tar.bz2
This is just scratching the surface of what can be done with the new iAppTM feature in v11. I didn’t even cover the ability to use presentation and implementation libraries, but that will be covered in due time. If you’re impatient, there are already several examples (including this one here) in the codeshare.
Related Articles
line 101 syntax error near unexpected token 'do
please help. Thanks
/bin/bash
in front of the exact command.
where I'm stuck is that despite this file existing in the /etc/cron.d folder the script is not running at all. If I remember correctly (for linux anyway) this is just a holder that other cron folders will call. So I created a symbolic link to the cron.daily folder and set it to run, but it never fired off...
I am new to this. I just got a task to set up a backup strategy for our F5 systems. We have LTM and APM version 11.1
Can you confirm that i can use this script to do the backup? Is there a updated version of the scripts that fix the issues pointed by other users on this thread?
Thanks a lot for the good work.
Etienne