Forum Discussion

swo0sh_gt_13163's avatar
swo0sh_gt_13163
Icon for Altostratus rankAltostratus
Jul 20, 2014

F5 Auto backup script for SCP for V10 and 11.

Hello Guys,

 

I have tried looking for the subjected topic within DevCentral, but unfortunately that didn't help. (I must be doing something wrong for sure). By the way I couldn't find any script for SCP which can be use for version 10.

 

My requirement is to craft a script for SCP server which executes on daily basis. The customer is having 2 separate clusters, one is running on v10, another on 11.

 

Is there any script which I can use for my requirement?

 

Thank you,

 

  • The script just saves the files locally I'm afraid.

    Storing a username and password in this file would not be a good idea. You'd want to set-up key-based authentication as explained here: https://blogs.oracle.com/jkini/entry/how_to_scp_scp_and.

    Then it would be as simple as adding something like this before the end of the script;

    scp "${UCS_FILENAME}.ucs" username@hostname:/dir/location/ 
    scp "${UCS_FILENAME}.scf" username@hostname:/dir/location/
    
  • Trying again, slightly modified and some formatting errors corrected;

    Login to the device using the admin account, then move to the admin home directory and create a file using vi:

    cd /home/admin
    vi bigipbackup.sh
    

    Paste the following into the console:

    !/bin/bash
    /admin/home/bigipbackup.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`"
    Note the correct ` character must be used above,
    this can be found near the top left of most keyboards
    just under the [ESCAPE] key. 
    
    Uncomment the following line for troubleshooting
    echo $DATETIME
    
    Create filename variable
    UCS_FILENAME="${DATETIME}_$HOSTNAME"
    
    Uncomment the following line for troubleshooting
    echo $UCS_FILENAME
    
    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 (31 days) to whatever suits you
    find /var/local/ucs/ –mtime +31 -delete
    EOF
    

    Save the file and exit vi;

    :w:q
    

    Then make it executable:

    chmod 711 bigipbackup.sh
    

    Then modify the admin user’s cron table as necessary based on your needs (paste in the relevant line, not all of them);

    crontab –e
    
    @daily /home/admin/bigipbackup.sh >/dev/null 2>&1 Every day
    @weekly /home/admin/bigipbackup.sh >/dev/null 2>&1 Every week
    @monthly /home/admin/bigipbackup.sh >/dev/null 2>&1 Every month
    
  • There's also an iApp from Jason Rahm, here: https://devcentral.f5.com/tech-tips/articles/scheduling-big-ip-configuration-backups-via-the-gui-with-an-iapp.

    Here's what I use but unfortunately no off box SCP, shouldn't be too hard to add;

    Login to the device using the admin account, then:

    cd /home/admin
    vi bigipbackup.sh
    

    Paste the following into the console:

    !/bin/bash
    /admin/home/bigipbackup.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`"
    Note the correct ` character must be used above,
    this can be found near the top left of most keyboards
    just under the [ESCAPE] key. 
    
    Uncomment the following line for troubleshooting
    echo $DATETIME
    
    Create filename variable
    UCS_FILENAME="${DATETIME}_$HOSTNAME"
    
    Uncomment the following line for troubleshooting
    echo $UCS_FILENAME
    
    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 (31 days) to whatever suits you
    find /var/local/ucs/ –mtime +31 -delete
    EOF
    
    Save the file and then make it executable:
    chmod 711 bigipbackup.sh
    

    Then modify the admin user’s cron table as necessary based on your needs (paste in the relevant line, not all of them);

    crontab –e
    
    @daily /home/admin/bigipbackup.sh >/dev/null 2>&1 Every day
    @weekly /home/admin/bigipbackup.sh >/dev/null 2>&1 Every week
    @monthly /home/admin/bigipbackup.sh >/dev/null 2>&1 Every month
    
  • Actually I just need to have a solution where I can automate the backup on a regular frequency to an SCP server.

     

    Btw, thanks for sharing F5-Config-Backupv3.

     

  • Dear Bhattman,

     

    Thank you for your update. I have tried to use this script, however got multiple syntax errors while executing. Is there a way where I can have a tested script where I can replace IP address and other relevant information respect to SCP server? Sorry but I don't understand code :(

     

  • Hi Swo0sh,

     

    Here is the following script: Click Here

     

    You can store the script in /etc/cron.daily or cron.hourly or cron.monthly and make sure it's an executable.

     

    I hope this helps

     

    -=Bhattman=-