# Automatic Backup and trasferring the UCS file to FTP server .

**URL:** <https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195>\
**Category:** Technical Forums\
**Tags:** management, application-delivery, ltm, cisco\
**Created:** [March 9, 2014, 11:28am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195 "2014-03-09T11:28:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indrajit\_Basak](https://avatars.discourse-cdn.com/v4/letter/i/59ef9b/32.png) [@Indrajit\_Basak](https://community.f5.com/u/Indrajit_Basak)\
**Post date:** [March 9, 2014, 11:28am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/1 "2014-03-09T11:28:14Z")

</div>

Hi, Can anybody help me to write script for automatic transfer of backup files to FTP server . My Automatic backup i sworking fine and it is stored locally . Now i want to transfer those UCS files to FTP server .

---

<div class="post-metadata">

**Author:** ![boneyard](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/boneyard/32/20419_2.png) [@boneyard](https://community.f5.com/u/boneyard)\
**Post date:** [March 9, 2014, 12:19pm UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/2 "2014-03-09T12:19:11Z")

</div>

there are several scripts available already, have a look at them and you will find the code you need to ftp.

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

---

<div class="post-metadata">

**Author:** ![Patrik\_Jonsson](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/patrik_jonsson/32/20827_2.png) [@Patrik\_Jonsson](https://community.f5.com/u/Patrik_Jonsson)\
**Post date:** [March 9, 2014, 12:20pm UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/3 "2014-03-09T12:20:50Z")

</div>

Hi!

Have you considered using scp? There’s available automated backup scripts transferring files to remote locations right here at devcentral. Personally I’m using a older, but modified, version of Colin Stubbs script:

> **[DevCentral - An F5 Technical Community](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

Works like a charm!

Otherwise the F5 unit has both ftp and ftps. There’s a good guide on how to transfer files via scrips here:

> **[Using ftp in a shell script](https://bruceediger.com/scripting.ftp.html)**
>
> Unix shell script code using ftp client

Good luck!

/Patrik

---

<div class="post-metadata">

**Author:** ![Patrik\_Jonsson](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/patrik_jonsson/32/20827_2.png) [@Patrik\_Jonsson](https://community.f5.com/u/Patrik_Jonsson)\
**Post date:** [April 26, 2014, 2:31am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/4 "2014-04-26T02:31:27Z")

</div>

It did not work for me either in v11 without modifications, but if you follow these steps it should work.

Make sure you’re root.

Run this to create the scp config file:

```tcl
echo 'Host *
User f5archive
PasswordAuthentication no
StrictHostKeyChecking yes
IdentityFile /root/.ssh/f5archive_dsa
Port 22
Protocol 2
Ciphers aes128-cbc,aes192-cbc,aes256-cbc' > /root/.ssh/f5archive_config

```

Create the directories used to store the script and the backups

```tcl
mkdir /var/local/bin
mkdir /var/local/backups

```

Schedule the script in cron (this example schedules it at 05:00, every day):

```tcl
echo 'SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HOME=/var/tmp
0 5 * * * root /bin/bash /var/local/bin/f5backup.sh 1>/var/tmp/f5backup.log 2>&1' > /etc/cron.d/f5backup

```

Create the keys and copy them to your server (replace user and IP):

```tcl
ssh-keygen -t rsa -f /root/.ssh/f5archive_dsa -N ''
ssh-copy-id -i /root/.ssh/f5archive_dsa.pub myuser@10.10.10.10

```

A modified version of the script can be found below.

Change this row to whatever you need (this is the remote server + path where you will store your backups):

```tcl
SCP_DESTINATION="myuser@10.10.10.10:/my/path/to/bigipbackups/${HOSTNAME}"

```

Then copy the modified version of the script below to /var/local/bin/f5backup.sh.

```tcl
!/bin/bash
 f5backup.sh
 Copyright (C) 2010 Colin Stubbs 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see 

 Additional files you'll need to create, example content:

  /etc/cron.d/f5backup
 SHELL=/bin/bash
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=user@somewhere
 HOME=/var/tmp
 0 0 * * * root /bin/bash /var/local/bin/f5backup.sh 1>/var/tmp/f5backup.log 2>&1
  EOF

  /root/.ssh/f5archive_config

 Host *
   User f5archive
   PasswordAuthentication no
   StrictHostKeyChecking yes
   IdentityFile /root/.ssh/f5archive_dsa
   Port 22
   Protocol 2
   Ciphers aes128-cbc,aes192-cbc,aes256-cbc
   UserKnownHostsFile /root/.ssh/f5archive_host

  EOF

 REQUIRES:
  F5 BIG-IP 10.2.x

 Debug ? Set to non-blank if so.
DEBUG=

 Current date/time stamp
DATETIME="`date +%Y%m%d%H%M%S`"

 Base f5backup.sh working directory
OUT_DIR='/var/tmp'

 Unique temporary output location
TEMP_DIR="`mktemp -d ${OUT_DIR}/f5backup.XXXXXXXXXX`"

 Backup options
 Export a UCS archive
DO_UCS='1'
 Export a single config file
DO_SCF=
 Export SCF with oneline bigpipe statements
DO_SCF_ONELINE='0'

 Use SCP with pubkey to export to remote system
DO_SCP_EXPORT=0

 SCP options must be set if you want to use this
SCP_OPTIONS=""
 Destination list, can be a list of username:IPorHostname if you want to
 transfer to multiple destinations. Same public key used for auth to all.
 ** MAKE SURE YOU INCLUDE :<%DIRECTORY%> HERE
SCP_DESTINATION="myuser@10.10.10.10:/my/path/to/bigipbackups/${HOSTNAME}"
 All SCP options should be encapsulated in a special config file
SCP_CONFIG="/root/.ssh/f5archive_config"

 UCS output location
UCS_FILE="${TEMP_DIR}/ucs.${DATETIME}.backup"

 Logfiles output location
LOGZIP_FILE="${TEMP_DIR}/log.${DATETIME}.tar.bz2"

 ** If blank this will not be used
 Encrypt UCS archive with passphrase
UCS_PASSPHRASE=

 SCF output location
SCF_FILE="${TEMP_DIR}/scf.${DATETIME}.backup"

 Local archive location
 ** If this variable is blank, or the destination is not writable then
    this script will not copy the backup to the local archive.
LOCAL_ARCHIVE="/var/local/backups"

 Remove all older local backups than this many days
LOCAL_CLEANUP_DAYS=7

 Name of compressed backup archive to produce
OUTPUT_FILE="${HOSTNAME}-${DATETIME}.tar.bz2"

if ["${DEBUG}x" != "x"] ; then
 for i in HOSTNAME DATETIME OUT_DIR TEMP_DIR DO_UCS DO_SCF DO_SCF_ONELINE DO_SCP_EXPORT SCP_DESTINATION SCP_OPTIONS SCP_CONFIG ASM_POLICY_LIST UCS_FILE UCS_PASSPHRASE SCF_FILE LOCAL_ARCHIVE OUTPUT_FILE ; do
   eval var=\$$i
   echo "${i} = $var"
 done
fi

function usage {
echo "Usage: f5backup.sh"
exit 0
}

function export_scf() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
  if ["${DO_SCF}x" != "x"] ; then
   if ["${DO_SCF_ONELINE}x}" != "x"] ; then
          bigpipe export oneline "${SCF_FILE}"
   else
          bigpipe export "${SCF_FILE}"
   fi
 fi
}

function copy_logs() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
  cp -R /var/log "${TEMP_DIR}"
}

function export_ucs() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
  if ["${DO_UCS}x" != "x"] ; then
   if ["${UCS_PASSPHRASE}x" != "x"] ; then
    bigpipe config save "${UCS_FILE}" passphrase "${UCS_PASSPHRASE}"
   else
     tmsh save /sys ucs "${UCS_FILE}"
   fi
 fi
}

function create_backup() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
 tar -j -c -f "${OUT_DIR}/${OUTPUT_FILE}" -C "${TEMP_DIR}" .
}

 Transfer backup archive to offsite location/s
function backup_remote() {
if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
if [-f "${OUT_DIR}/${OUTPUT_FILE}"] ; then
  if ["${DO_SCP_EXPORT}x" != "x"] ; then

    echo "Copying to remote archive ${SCP_DESTINATION}${OUTPUT_FILE}"

    if ["${DEBUG}x" != "x"] ; then echo "Exec: /usr/bin/scp ${SCP_OPTIONS} -F ${SCP_CONFIG} ${OUT_DIR}/${OUTPUT_FILE} ${SCP_DESTINATION}" ; fi
    /usr/bin/scp ${SCP_OPTIONS} -F "${SCP_CONFIG}" "${OUT_DIR}/${OUTPUT_FILE}" "${SCP_DESTINATION}" || echo "Error: SCP ${OUT_DIR}/${OUTPUT_FILE} ${SCP_DESTINATION} failed!"

  fi
else
  echo "Error: ${OUT_DIR}/${OUTPUT_FILE} doesn't exist, something has gone wrong!"
fi
}

function backup_local() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
 if ["${LOCAL_ARCHIVE}x" != "x"] && [-d "${LOCAL_ARCHIVE}"] ; then

   echo "Copying to local archive ${LOCAL_ARCHIVE}/${OUTPUT_FILE}"

  if [! -d "${LOCAL_ARCHIVE}"] ; then
    mkdir "${LOCAL_ARCHIVE}"
    if [${?} -ne 0] ; then
      echo "Error: ${LOCAL_ARCHIVE} doesn't exist and I can't create it."
    fi
  fi

  mv -f "${OUT_DIR}/${OUTPUT_FILE}" "${LOCAL_ARCHIVE}"/

  find "${LOCAL_ARCHIVE}" -type f -mtime +${LOCAL_CLEANUP_DAYS} -exec rm -v -f {} \;
 fi
}

 Cleanup what this script has done
function cleanup() {
 if ["${DEBUG}x" != "x"] ; then echo "in ${FUNCNAME}(${*})" ; fi
 rm -rf ${TEMP_DIR}
}

 Sanity checking
 1. Must be run as root
if ["`id -u`x" != "0x"] ; then
 echo "Error: You need to run this script as root."
 exit 1
fi

 2. Command line args
  not applicable yet

 3. Temp dir must exist
if [! -d "${TEMP_DIR}"] ; then
  echo "Error: ${TEMP_DIR} was not created for some reason. Fix this issue and try again."
 exit 1
fi

echo "${0} start `date +%Y%m%d%H%M%S`"

export_ucs
export_scf
copy_logs

create_backup

backup_remote
backup_local

cleanup

echo "${0} finish `date +%Y%m%d%H%M%S`"

 EOF

```

Good luck!

/Patrik

---

<div class="post-metadata">

**Author:** ![vincent119\_9651](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@vincent119\_9651](https://community.f5.com/u/vincent119_9651)\
**Post date:** [June 11, 2014, 4:16am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/5 "2014-06-11T04:16:04Z")

</div>

[http://vincent119.blogspot.tw/2007/05/backup-f5-bigip-config.html](http://vincent119.blogspot.tw/2007/05/backup-f5-bigip-config.html)

---

<div class="post-metadata">

**Author:** ![Mahmoud\_Eldeeb](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mahmoud\_Eldeeb](https://community.f5.com/u/Mahmoud_Eldeeb)\
**Post date:** [December 17, 2014, 9:10pm UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/6 "2014-12-17T21:10:27Z")

</div>

I prefer to go with Config Backup for F5 utility its a VM appliance with GUI interface and very easy to manage.find it in below link [http://sourceforge.net/projects/f5configbackup/](http://sourceforge.net/projects/f5configbackup/)

---

<div class="post-metadata">

**Author:** ![ogozar\_275571](https://avatars.discourse-cdn.com/v4/letter/o/a6a055/32.png) [@ogozar\_275571](https://community.f5.com/u/ogozar_275571)\
**Post date:** [September 12, 2017, 2:09am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/7 "2017-09-12T02:09:27Z")

</div>

Hello, when I generate an automatic backup it shows me this error when I execute the script:

Error, invalid characters in UCS file name. The dash, period, forward-slash, plus sign, and underscore are the only special characters allowed.

What could be the problem?

---

<div class="post-metadata">

**Author:** ![Allwyn\_Mascaren](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@Allwyn\_Mascaren](https://community.f5.com/u/Allwyn_Mascaren)\
**Post date:** [April 9, 2019, 11:35am UTC](https://community.f5.com/t/automatic-backup-and-trasferring-the-ucs-file-to-ftp-server/41195/8 "2019-04-09T11:35:09Z")

</div>

spam blog
