cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Problem this snippet solves:

This script makes a backup of all iRules of every host in the tuple. It will create a folder with the hostname/partition and there a file for every iRule. 0151T000003d9EWQAY.png

How to use this snippet:

Change parameters in multi-backup.py

host:$ python ./multi-backup.py

Code :

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Used to backup iRules on all F5 Loadbalancers
"""

__author__ = "Yannic Schneider"
__license__ = "WTFPL"
__email__ = "v@vendetta.ch"

###############################################################################
# CODE
###############################################################################

import bigsuds
import sys
import os

# Globals
hosts = ('10.x.x.1','10.x.x.2',)
user = ''
password = ''

# Loop trough hosts
for host in hosts:
    try:
        b = bigsuds.BIGIP(
            hostname=host,
            debug=True,
            username=user,
            password=password
        )
        print('Debug: Backup of host='+host)
    except Exception, e:
        print e

    # Set system partition
    b.System.Session.set_active_folder("/Common")

    # Get all rules
    allr = b.LocalLB.Rule.query_all_rules()

    if not os.path.isdir('./'+host):
        os.mkdir('./'+host)

    if not os.path.isdir('./'+host+'/Common'):
        os.mkdir('./'+host+'/Common')

    for rule in allr:
        f = open("./"+host+rule['rule_name'],'w+')
        f.write(rule['rule_definition'])
        f.close

Tested this on version:

11.0
Version history
Last update:
‎09-May-2017 05:32
Updated by:
Contributors