Forum Discussion

Mostafa_Ezzat_1's avatar
Mostafa_Ezzat_1
Icon for Nimbostratus rankNimbostratus
Mar 05, 2019

automated Backup Scirpt

iam trying to taking automated backup and transfer it to a remote ftp server using running the script using the sh script.sh its runs perfectly fine and when trying to added the script in the crontab the ucs file is not transfered to the the remote server . here is the script iam using

!/bin/bash

today_ucs="

date "+%m_%d_%y"
.ucs" today_config="
date "+%m_%d_%y"
.txt" log_file="
date "+%m_%d_%y"
.log" tmsh save /sys ucs /root/daily_backup/$today_ucs tmsh /show running-config one-line >$today_config HOST='x.x.x.x' USER=user PASSWORD=password

ftp -inv $HOST << EOF 1>&2 >$log_file ascii quote USER $USER quote PASS $PASSWORD cd DIR put $today_ucs put $today_config bye EOF rm -rf $today_ucs rm -rf $today_config

  • FTP is pretty tricky to get right in scripts - I have used expect before but it takes a lot of doing. Better to use iControl REST. Use my iCR Python module and use the script below:

    !/usr/bin/env python
    from iCR import iCR
    bigip = iCR("172.24.9.132","admin","admin")
     Create new UCS
    data = { "command": "save", "name": "myTestUCS"}
    ucs = bigip.create("sys/ucs",data)
     Move UCS to /shared/images
    data = { "command": "run", "utilCmdArgs": "-c 'mv /var/local/ucs/myTestUCS.ucs /shared/images'"}
    mv = bigip.create("util/bash",data)
     Download UCS
    download = bigip.download("myTestUCS.ucs")
     Delete UCS from /shared/images
    data = { "command": "run", "utilCmdArgs": "-c 'rm /shared/images/myTestUCS.ucs'"}
    rm = bigip.create("util/bash",data)
    

    I'm sure you can see the parts which you need to change for your own environment.