For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Stephen_Spence_'s avatar
Stephen_Spence_
Icon for Nimbostratus rankNimbostratus
Sep 04, 2013

Backup script for F5 LTM and FTP the UCS off to another server

I am trying to automate backups on my F5 LTMs. I have downloaded the following script and tried to run it. For Version 11.x branch https://devcentral.f5.com/wiki/AdvDesignConfig.LTM_Backup_Shell_Script.ashx But it keeps throwing errors

 

With version 10 backup script the bagpipe backup script worked fine. Now that we are running v11 I can't seem to get it to run. Any assistance would be appreciated.

 

14 Replies

  • here is the code and below is the error:

    !/bin/sh -x Name: backup_cron_scriptv11.sh BIG-IP Backup Script This script automates LTM v11 Backups and saves the files with hostname and date off to an FTP server version 1.0 Author: Bhattman Original Date: 01/07/10 Modified by Yih Wen 30/11/12

    tmsh save /sys ucs /var/tmp/BIG-IP_backup 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

    Added By Ed Elias 11/26/02

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

    export MName=xxxxxxx export Log=/var/tmp/log.bigip

    export UserName=xxxxx export UserPassword=xxxxxx

    Added and Updated by Ed Elias 11/14/07

    export Machine1f2=$aa export Machine1f3=$c export Machine1f4=$ff ftp -nvd ${MName} <<-END 1>&2 > ${Log} user ${UserName} ${UserPassword} bin put ${b} ${Machine1f2} put ${cc} ${Machine1f3} put ${f} ${Machine1f4} quit END rm -f ${b} rm -f ${cc} rm -f ${f} RTN_CODE=$?

    exit $RTN_CODE

    Error I am receiving: command not found: command not found4: " unknown property ': not a valid identifierort: ': not a valid identifierort: ': not a valid identifierort: mv: target\r' is not a directory command not found1: tar: Removing leading /' from member names tar: \r: Cannot stat: No such file or directory tar: Error exit delayed from previous errors ': not a valid identifierort: ': not a valid identifierort: mv: target\r' is not a directory command not found6: command not found8: ': not a valid identifierort: ': not a valid identifierort: cp: target \r' is not a directory : command not found2: ': not a valid identifierort: command not found2: ': not a valid identifierort: ': not a valid identifierort: command not found5: ': not a valid identifierort: ': not a valid identifierort: command not found8: ': not a valid identifierort: ': not a valid identifierort: ': not a valid identifierort: `

    1. Create directory on BIG-IP /shared/ucs/ as root: mkdir /shared/ucs
    2. Copy the backup script (backupucs) as root via SCP to /shared/backupucs and make it executable: chmod +x /shared/backupucs
    3. Create a SSH public keys as root: ssh-keygen -t dsa
    4. Export the local root public key for remote login on the target / backup server: ssh-copy-id -i ~/.ssh/id_dsa.pub remote_user@your_backup_server
    5. Modify cron on BIG-IP as root: crontab -e

    cron tab for root

    1-59/30 * * * * /usr/bin/diskmonitor

    00 5 * * * /shared/backupucs

    The following script will now be triggered by cron each morning 5 a.m..

    A current .ucs file with hostname and timestamp in its name will be created and copied to the target server via SCP.

    Files older than 7 days will be deleted.

    Don´t forget to modify the passphrase. 😉

    As the archive contains the private keys, encrypted export should be mandatory.

     

     

     

    \! /bin/bash
        time=`date +%Y_%m_%d_%H%M`
        unit=`tmsh list sys global-settings one-line | grep -oP '(?<=hostname\s)[^\.]*'`
        tmsh save /sys ucs /shared/ucs/autoarchive_${unit}_${time}.ucs passphrase 'topsecret'
        scp /shared/ucs/autoarchive_${unit}_${time}.ucs remote_user@your_backup_server:/data/config/loadbalancer/
        find /shared/ucs/ -name "autoarchive*" -mtime +7 -ls >> /var/log/ucsdelete
        find /shared/ucs/ -name "autoarchive*" -mtime +7 -ls -exec rm -f {} \;
        

     

     

     

  • First of all, thanks for all your replies. Here is the problem that we were having with the script not FTPing: Firewall is blocking the passive mode ftp transfer.

     

    http://blogs.msdn.com/b/asiatech/archive/2009/04/30/iis-ftp-service-hang-due-to-ports-contention-in-passive-mode.aspx

     

    We can request a change for the firewall config to be fixed so that FTP works transparently.

     

    In the mean time, I added a "passive" command in the ftp blurp in the script. This command is a toggle switch command, and when it is run for the first time, it turns off the passive mode (i.e. all ftp transfers take place in active mode). With FTP mode active, script is working fine.

     

    Once again thanks.

     

  • This scripts works with V9 and V10. create the script called ftpbackup.sh "vi ftpbackup.sh" !/bin/sh ftp server ip address HOST='10.2.2.5' ftp user name USER='ftp_user' ftp password PASSWD='passw0rd1234' check if LTM is active node or stanby node A=$(bigpipe failover show | grep -c "active") store date, to appended to end of the ucs file D=$(date +%d_%m_%Y_%H-%M-%S) store the hostname of the ltm node U=$(uname -n) remove all old ucs files rm -f /var/local/ucs/*.ucs case ${A} in if ltm is active do a config sync and wait 60 sec and generate a ucs file "1") bigpipe config sync; sleep 60; bigpipe config save $U-$D; echo " active unit";; if lmt not active wait before creating the ucs file "0") sleep 180; bigpipe config save $U-$D; echo "Standby unit";; esac ftp to remote ftp server ftp -inv $HOST <